Redirect non-www Domain to the www Domain and Avoid Duplicate Content

A webpage or the website itself, can have more than one version of the URL pointing to it. This creates some issues for a search engine and the for the SEO of the website itself, often referred to as the canonicalization issue. Canonicalization  or c14n, in the world of websites, is the process in which the best URL is chosen for a landing page where there is several possibilities. One prime example is the homepage of the website, which usually has two equivalent URLs pointing to it.

As an example, if the domain name of your site is “mysite“, then you might be aware that both http://www.mysite.com and http://mysite.com point to the same website/webpage. And technically these are two different URLs which happens to point to the same webpage in this case. It is quite possible to configure it such that they do serve two different page, if needed. That means, www.mysite.com and mysite.com are infact two different websites.

Even though this is not necessarily an issue, it is undesirable from the perspective of the website SEO. Some of the obvious issues being…

Duplicate Content

In the eyes of the search engines, the two URLs are different which happens to serve identical content. Most modern day search engines are aware of the issue and will do some optimization to avoid penalizing the site for the duplicate content. But you are usually better off if you can reliably indicate that you prefer one form of the URL over the other and allow the search engine to index the content correctly against just one preferred URL.

Loss of Backlinks

When others generate links back to your website, they could use either of the URLs the one with the www or the non-www version of the domain name. Unless you specify that both of these URLs are one and the same, the search engines could count them separately thus reducing the link juice or link popularity (or page rank) of your webpage.

Split Data in Analytic Software

Depending on the analytic software you use, your webpage data will be split between the two forms of the URL. This is a similar issue to the one mentioned above where your backlinks are split thus not giving you the complete credit for the backlinks. Even though, it probably is not that much harder to add up your data for the two different URLs, it definitely does not make it easier to analyze the data.

 

So, the first thing to find out is if your website is properly redirected so that non-www URL redirects correctly to the www version (or vice-versa). There are couple of easy ways to find this out

Using a Browser

Input your website URL without the www (for example, http://mysite.com) into the browser and see it redirects to the www version. If it does you will see that the browser had infact rewritten the URL you had typed in the location bar into the www version. Also, input the URL with the www (eg. http://www.mysite.com) and determine the URL was redirected by the browser.

Use a website analysis tool

There are quite a few website analysis tools available online, often free that will analyse your website and provide you with suggestions to improve your website SEO. Almost all of these tools will provide with this canonicalization information. Two of the analysis tool that I recommend is Pear SEO Analysis and Woo Rank. You should see something similar as the screenshot below, if you have configured this correctly.

WooRank analysis showing the www compliance information

 

Use Google Search

Do a search for your indexed page and see if Google lists any of your webpage twice, once with the www and once without. You can see a list of your indexed pages by using the site operator in the search..Search for something like site:mysite.com. This is usually not a reliable test, because Google donot list all the indexed pages to start with or Google search algorithm could have deduced one of your URL as the primary URL and used it.

 

So now assuming that you have verified that your website does not do a proper redirection in place, let’s see what the best way is to fix this. The most recommended solution to this is to do a permanent redirection also known as a 301 redirect to your preferred domain.  This is the best and the easy way to fix this. Also, it is a search engine friendly way of doing it as search engines understands the redirection and passes all the link juice to your preferred URL.

It doesnot really matter which version of the URL you decide to redirect to, it is more of a personal choice. I prefer the www version of the URL, but you could choose the non-www version. If your website has been around for a while or you have plenty of backlinks, then find out which version of the URL has the most backlinks and use that as the default.

After you have decided on your preferred version, the next step is to find your .htaccess file in the website folder. Usually this file exists in your web root folder.  If you cannot find it, make sure that you have selected the option to display hidden files. It is also quite possible you donot currently have one, in which case you could easily create one with the same name.

If there is already a file named .htaccess with any code in it, make sure that you make a copy of it as a backup. This will allow you to easily restore the older working version if you do mess anything up.

Configure the www version as the preferred domain

This means it will redirect the non-www version of the URL to the www version. That is, http://mysite.com will be redirected to http://www.mysite.com

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

 

Configure the non-www version as the preferred domain

This will redirect the www version of the URL to the non-www version. That is, http://www.mysite.com will be redirected to http://mysite.com

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

Do not forget to replace the word mysite with the actual domain name of your website.
Ensure that your hosting provider has the Apache rewrite module turned on. Almost all providers do have this turned on by default, if you are not sure ask your provider. This is a definite requirement for the above code to work correctly.
In addition to configuring your web server with the code above, you should also make sure that you set the preferred domain in the Google webmaster tools to the same version you configured in the .htaccess file.