07/06/2015

Using .htaccess to redirect www to non-www or vice versa

7

To redirect from www to non-www, edit your .htaccess file suc as:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

and to redirect from non-www to wwww:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

About Author Mr.Bazz

Hi thanks for dropping by. Please share the content if you think there is someone who will appreciate it.

Leave A Comment

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