I’ve been trying to collect analytics for my website and realized that Google analytics was not setup to capture data for visitors to http://www.example.com (it was only setup for example.com). I noticed that many sites will redirect me to http://www.example.com when I type only example.com. However, stackoverflow does exactly the opposite (redirects http://www.stackoverflow.com to just stackoverflow.com).
So, I’ve decided that in order to get accurate analytics, I should have my web server redirect all users to either http://www.example.com, or example.com. Is there a reason to do one or the other? Is it purely personal preference? What’s the deal with www? I never type it in when I type domains in my browser.
History lesson.
There was a time when the Web did not dominate the Internet. An organisation with a domain (e.g. my university, aston.ac.uk) would typically have several hostnames set up for various services: gopher.aston.ac.uk (Gopher is a precursor to the World-wide Web), news.aston.ac.uk (for NNTP Usenet), http://ftp.aston.ac.uk (FTP – including anonymous FTP archives). They were just the obvious names for accessing those services.
When HTTP came along, the convention became to give the web server the hostname ‘www’. The convention was so widespread, that some people came to believe that the ‘www’ part actually told the client what protocol to use.
That convention remains popular today, and it does make some amount of sense. However it’s not technically required.
I think Slashdot was one of the first web sites to decide to use a www-less URL. Their head man Rob Malda refers to ‘TCWWW’ – ‘The Cursed WWW’ – when press articles include ‘www’ in his URL. I guess that for a site like Slashdot which is primarily a web site to a strong degree, ‘www’ in the URL is redundant.
You may choose whichever you like as the canonical address. But do be consistent. Redirecting from other forms to the canonical form is good practice.