Redirecting www to non-www
To avoid duplicate content in search engines you can force users to use either the www or the non-www version of your website domain.
Redirecting www to non-www and reverse (solved)
If you want to redirect all non-www requests to your site to the www version, add the following code to your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Adversely
Redirecting www to non-www
If you want to do the opposite, use the following code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]
Redirecting www to non-www and reverse (solved)
If you want to redirect all non-www requests to your site to the www version, add the following code to your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Adversely
Redirecting www to non-www
If you want to do the opposite, use the following code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]
No comments