.htaccess Redirect WWW / Non-WWW

Issue: Apache server, redirect www to non-www domain and visa versa.

Solution:

WWW to Non-WWW

# BEGIN 301 redirect www to non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.DOMAINNAME\.com$
RewriteRule ^/?$ "http\:\/\/DOMAINNAME\.com\/" [R=301,L]
# END 301 redirect www to non-www

Non-WWW to WWW

# BEGIN 301 redirect non-www to www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^DOMAINNAME\.com$
RewriteRule ^/?$ "http\:\/\/www\.DOMAINNAME\.com\/" [R=301,L]
# END 301 redirect non-www to www

Leave a comment

BlogLogistics