November 1, 2012

How To Solve WWW Or Non WWW Duplicate Content Issue

|
If you checked your website or blog domain with the duplicate tool called Virante and you saw this remark:

WWW/NonWWW Header Check: FAILED
Your site is not returning a 301 redirect from www to non-www or vice versa. This means that Google may cache both versions of your site, causing sitewide duplicate content penalties


Don't panic. Here are 2 methods which you can do to solve this problem:

Method 1. Add code to .htaccess File

You just add the following code to your .htaccess file.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]


You can use also use either of these codes:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]


or this:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]


Note: Change yourdomain and www.yourdomain in the code to your ACTUAL domain.

If you are newbie, here is a post which shows you how to find .htaccess file.



Method 2. Add A Canonical Tag

You just add the following code within the <head> section.

<link rel="canonical" href="yourdomain" />

Note: Change yourdomain to your ACTUAL domain or URL.

These are two methods to overcome the www vs non-www duplicate content problem.