Tuesday, October 16, 2012

How to check and fix Domain Canonicalization (www)

It's a common configuration in web servers to point both urls of www.example.com and example.com to same content. This is a bad practice in terms of SEO because they regarded as duplicate content. If you have access to the .htaccess and assuming your Apache server has mod_rewrite enabled, you can add following lines to redirect traffic and issue a 301 (Moved Permanently).
I prefer my site addresses without www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

If you like to have your addresses with www use the following
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

If you have any sub domains like blog.example.com do not use the above code.

No comments:

Post a Comment