Redirect www to non-www, or Vice-Versa on Apache Server

Redirect www to non-www, or Vice-Versa on Apache Server

Add the following to the websites root .htaccess file.
Redirect to non-www version:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ http://yourwebsite.com/$1 [L,R=301,NC]
</IfModule>

Redirect to www version:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ http://www.yourwebsite.com/$1 [L,R=301,NC]
</IfModule>

Leave a Reply