With SEO, you need to make sure that you only have one domain with the content of your site. All other domains need to have 301 redirects to the initial domain. Therefore you need Non www to www 301 redirects - all non www should be redirected to the www versions of the domains.

For specific code for your site, see the redirect checker

ie the url in your address bar should change from:

  • http://domain.com to http://www.domain.com.

All url’s inside the domain should redirect to their www equivalent.

  • http://domain.com/widgets.html to redirect to http://www.domain.com/widgets.html

Background reading

Google does not like duplicate content. When there are both www and non www versions of your site able to be accessed, you have duplicate content available to Google.

So what does Google do?

  • You can use the Google webmasters tool to tell Google to use your www or non www version of the website
  • You may have some links coming into your site with the www and others with the non www version of your link.
  • You are effectively splitting your Google Page Rank between the two sites (each www and non www is treated as a site in its own right).
  • If you redirect your non www version, then your www has the benefit of both sets of links.
  • According to Google, which version is the best version of a site?
  • If you have built up many links onto the www version, and have that well ranked on Google, you could get a very powerful link onto your non www version. I have seen instances of where Google has then dumped all the rankings of the www version, then because there is only one powerful link into the non www version, not ranked the non www version. That one link has been enough to say to Google that the non www has been more powerful a site for that moment, but not powerful enough to rank it well.
  • Google will in general only rank one of the sites and over time will only cache one version of the site. Therefore, you want to make sure that it has got the version you have been working on.
  • I have seen instances where there are 4 versions of a site available - www, and non www of each .com and .co.nz country version. Google had started to take its cache off the main version and rankings and numbers of visitors to the sites had started to plummet. With redirects of each to one main site www site, the problem was able to be sorted.
  • When Google sees duplicate content, even a paragraph that returns the same 150 characters around the searchphrase, it will show one page, and not show the other page, not even in the 1000 pages that it lists for each search term. It will not just make them first and second for a search term.

Basically, it is not worth it to have duplicate content on your sites. While there may not be issues immediately, in the long run it is not safe, and it is very easily rectified.

The instruction is added to a file in the root directory of your website named “.htaccess”.


Here is a non www to www 301 redirect in “.htaccess”.

```RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain.com RewriteRule (.*) http://www.domain.com/$1 R=301,L]

## Windows .net / .asp

I have personally not done anything like this on a windows site, I leave it all to the developer of the asp/.net site. But I offer the following I have found from Google.

For details about isapi rewrites, check out [http://www.helicontech.com/isapi_rewrite/](http://www.helicontech.com/isapi_rewrite/)

Please see the following for a free isapi style of rewrites for windows .net - [/articles/ionic-isapi-rewriter/](Ionic Isapi Rewriter).

For a ISAPI rewrite please try out the following - please get back to me if it works, I don't have a windows machine to try it out on.

Add the following rule to your httpd.ini file:
RewriteCond Host: ^domain.com
RewriteRule (.*) http://www.domain.com [RP,L]

In iss, the R is for 302 redirects/temporary redirects, and the RP for 301 redirects/permanent redirects.

Quote: The Set Up Two Sites? In IIS Way per Matt Cutts blog Basically, it’s what it says it is. You set up two different sites, one for the non-www and one for the www version. Then, for the home directory of the non-www version, set up a redirect to the www version and ensure that it’s a permanent redirect for this resource (301).

.htaccess in inner directories

Now if you have an htaccess file in any one of the inner directories, then you need slight different code in there as well, since the htaccess works by itself, and does not inherit the upper level htaccess files:

Added to the htaccess file in your forums, or the equivalent in your “forum” directory.

```RewriteCond %{HTTP_HOST} ^domain.com RewriteCond %{REQUEST_URI} ^/forums/ RewriteRule (.*) http://www.domain.com/forums/$1 [R=301,L]

## Two domains pointing to same hosting account
I came across a situation where two domains were pointing at the same hosting account. I had to effectively change the url to the proper one if the domain name was the wrong one. By not having the ^ at the start of domain2, I was able to cater for both the non www and www versions of domain2.

```RewriteCond %{HTTP_HOST} domain2.com
RewriteRule (.*) http://www.domain.com/$1 R=301,L]

Hosting the subdomain in a directory of the main site

This subdomain was able to be accessed both via the main website, and with the subdirectory named as the subdomain.

ie both as http://www.domain.com/forum and http://forum.domain.com/

Obviously this was not appropriate, so used the following .htaccess to remedy it - placed into the htaccess file on the www.domain.com root folder (thanks vBSEO for helping me):

RewriteRule ^forum/(.*)$ http://forum.domain.com/$1 L,R=301]

Inside the subdirectory, you need the following added to your .htaccess file RewriteCond %{HTTP_HOST} !^forum.domain.com RewriteCond %{REQUEST_URI} ^/forum/ RewriteRule (.*) http://forum.domain.com/$1 R=301,L]

Redirecting from https to http on all but certain url’s

I obtained a secure server, and my host set it up so that the new ip number was looking into the same files as my normal site. Meant that my whole site could be accessed via https as well as http. Not the best for Google.

RewriteCond %{SERVER_PORT} 443 RewriteCond %{REQUEST_URI} !paypal/(.*)$ RewriteRule (.*) http://www.domain.com/$1 R=301,L]/

Now you have to do the same thing to make sure that the named directory can only be accessed via https.

RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} paypal/(.*)$ RewriteRule (.*) https://www.domain.com/$1 R=301,L]/

Strings used in .htaccess

Basically all the items in the php variable $_SERVER

including REQUEST_FILENAME REMOTE_ADDR - being the ip address HTTP_USER_AGENT REQUEST_URI - the url excluding the query string HTTP_REFERER - the domain name ie http://www.domain.com QUERY_STRING - the items starting with ? in the url SERVER_PORT - the port, especially useful if you want to check whether its via https - being port 443