.htaccess Redirection

1 ) How to redirect non www to www url in .htaccess

Add below mention code in your .htaccess  file

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

2 ) How to redirect ip to domain in .htaccess

Add below mention code in your .htaccess  file and change required changes.

RewriteCond %{HTTP_HOST} ^111\.111\.111\.111
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

 

Read More…

1 Comment. Leave new

Very nice solution. Really very usefull for php developer.

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *