URL Canonicalization – This is the process of choosing the best URL structure when there is a choice and then setting it and forgetting it.
For many of us, http://www.justinsblog.com and http://justinsblog.com look the same and more often than not, will take you to the same website. Generally speaking, most of us don’t give any thought at all to our URL structure or the difference between using www and not using www. However, the difference in your URL structure is VERY important when it comes to Search Engine Optimization and login cookies on your website.  Choosing the best URL structure for your website is very important.
Why should I choose a URL structure?
First and most importantly you should choose a canonical URL structure for the purpose of SEO. Because WWW. is essentially a sub-domain and search engines that will pick this up, (for example): justinsblog.com and www.justinsblog.com as two different domain names, likewise, search engines may split the page rank between the two if the same content is found on one version of the URL as found on another. This is considered page rank leakage and not something we want. If you have back-links going to both the www. and non-www version of your URL, one will benefit and the other will not.
Secondly, some search engines that pick up both URLs and backlinks coming into www and non-www versions of your URL with the same content, will consider this duplicate content and search engines don’t like duplicate content. Your site could be penalized because of this.
Third, you want to choose a canonical URL structure for the benefit of your visitors when it comes to navigating your site. If you use two different domain names and they are logged into one, they may visit the other URL and not be logged in. To them, it’s the same site but according to their browser cookies, they are not the same site. This could cause confusion.
WWW vs. NON-WWW URL, Which one should you choose?
WWW vs. Non-WWW is a good argument and can go both ways. If you ask me personally, I always choose the non-WWW version of the url for several reasons:
  1. Shorter Domain – I prefer shorter domain names so the search engines can get to the keywords after the domain name that tell them what the page is about. If the domain name is too long and full of session ID’s etc, then it may not be picked up quite as easily. There is no benefit at all having the www. in front of my domain name.
  2. Pure Domain Name – Using only the domain without the subdomain WWW is making use of the domain name in it’s purity. Being a domainer myself, I’m a purist when it comes to the use of domain names and don’t like the www. prefix.
  3. WWW Antiquated IMHO – When the web was in it’s infancy it was considered the World Wide Web, hence the WWW. Today it’s the Internet and in the past you’d seeWWW.mydomainname.com advertised on TV, today you rarely hear anyone say, ‘visit my site at www…‘. Now they just advertise the domain name only.
The use of www vs. non-www URL structure is a matter of personal choice. However if your website has been online a while and has back-links and internal links, and they were www. to begin with, then I’d recommend staying with the www. prefix and making that my canonical URL structure as you see on this site. However, if you are building a new site and don’t have a lot of back-links or page rank, then I’d suggest using the non-www version for all your URLs and linking.
On this site, we’re using WWW although I personally don’t use WWW on all new sites but since I started this site with www, I’ve decided to set it and forget it.
The important thing is to choose a URL structure and then stick with it!
How to I force it to one or the other?
On a Linux server you can use a 301 permanent redirect in your .htaccess file. This is the correct method that will allow search engines to combine the value of any incoming links to your site.  The .htaccess 301 redirect from non-www to the www version looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^justinsblog.com [NC]
RewriteRule ^(.*)$ http://www.justinsblog.com/$1 [L,R=301]
You could alternatively use something like this for WWW to Non-WWW:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Always backup your website before messing the the .htaccess file or at least back that file up and then see what works best for you.