Apache Redirects to WWW and without WWW version of website
October 17th, 2014It’s good for search engines, like Google, to only have one version of your website indexed. To Google, the www.yourdomain.com and yourdomain.com are not the same. You can use this code on Apache servers inside a .htaccess file. It’s worked for me on several different hosting companies.
To redirect to without www version:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.yourdomain\.com
RewriteRule ^(.*)$ http://yourdomain.com/$1 [R=permanent,L]
To redirect to the www version:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain\.com
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=permanent,L]
--------------
J. Olkoski
Aldebaran Web Design, Seattle
Jill Olkoski has a BS in Engineering, a BS in Computer Science and an MA in Clinical Psychology. She delights in using her advanced technical and psychological skills to help small business owners develop cost-effective and successful websites.