www/non-www canonization
SEO, internet January 30th, 2007To a reader, the following URLs may seem the same:
http://hatethegrind.com
http://www.hatethegrind.com
http://www.hatethegrind.com/index.php
However, to a search engine robot, those are three unique pages and as a result could have three different page ranks assigned to them. If you want all the backlinks associated with the three pages to all be counted towards the proper page, you will have to use some method to unify your website.
- The first method is by using PHP (or any other server side scripting)
- The .htaccess method
- Google Webmaster Tools Preferred Domain
You need some code that will check whether or not “www” is in the URL. If not, add it and redirect the user to the new page using a 301 redirect.
if(!stristr($_SERVER["HTTP_HOST"], 'www')){
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.hatethegrind.com" . $_SERVER["REQUEST_URI"]);
exit();
}
?>
Another way to accomplish this is to simply edit the .htaccess file on your webserver. By adding the following lines into your .htaccess file, you are essentially doing the same thing.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^hatethegrind\.com [NC]
RewriteRule ^(.*)$ http://www.hatethegrind.com/$1 [R=301]
If you log into the Google webmaster tools, you’ll find an option to set a preferred domain for your website. This is probably the easiest way to have Google index your results properly but will not redirect your users to the proper page. In other words, users will still be able to access your blog through the various URLs, and they will not be redirected. Google will however, attribute page rank properly.
Whichever method you choose is up to you, and all three should work. After doing all this, there are additional steps to ensure your site linking is optimized. Be sure to always link to the version you prefer when linking to other pages within your site. Good luck, and happy tweaking!
Other posts you may be interested in:






