To WWW or not to WWW

For almost every web site on the internet you can reach the home page by typing http://www.example.com or http://example.com—so what's the difference?

Remember those cookies we discuss in our Privacy Policy? Those small tidbits of information (max. 4093 bytes) used to keep track of users over a stateless protocol (HTTP/HTTPS).

Every time your web browser sends a request to a web site for information it sends along all cookies associated with that domain. Even if you are requesting a simple 128 byte response (geoip, javascript etc.) you could be sending 4 kilobytes of data to do it—and it's no model of efficiency to send almost 5000 bytes of data to get only 128 bytes in return.

The efficiency of any CDN can be greatly impacted by cookies.

What Cookies Get Sent?

Lets say you've registered the domain name example.com and you wish to set up a website example.com along with a couple of services (svc1.example.com and svc2.example.com). Whether or not you use the www. prefix for your website could have serious performance issues with your services and here's why.


Without the www, the same cookies sent to your site example.com will be sent to all sub-domains of that site. Your browser will happily send example.com cookies to all sites ending with “example.com”. Your services that don't use cookies will still be receiving them using up valuable bandwidth.

With the www., your website and your services become distinctly different locations, there is no ambiguity. No cookies intended for your website will be sent to any of your services and no cookies intended for your services will be sent to your web site. The services may use their own cookies, or none at all.

Note: This is not an error in the protocol, in some exceptional cases it may be desirable to share cookies across all sub-domains.

DNS

There seems to be some confusion around the net on how using WWW or not could have implications on scaling. As the argument goes, a domain name (example.com) must be associated with an A record (address), while the www prefix is associated with a CNAME record.

example.com   A  192.168.100.1
www           CNAME  example.com.

The argument continues on to imply that an A record limits your domain to a single server (no redundancy) while a CNAME record allows multiple hosts. This is simply not true.

For many years multiple A records have been allowed in DNS zones and used for redundancy. As much as I am in favor of using the WWW, this is simply not an argument for it. The following DNS Zone snippet is both acceptable, and common.

example.com   A  192.168.100.1
example.com   A  192.168.100.2
example.com   A  192.168.100.3
www           CNAME  example.com.

Search Engine Ranking

This is where your choice can have serious consequences.

With search engines, promotion reflects popularity—the more popular your web site is, the closer it gets to the top of the listings. Popularity is measured by both the quality and quantity of inbound links as well as traffic to your site.

So what if half your traffic was directed to www.yoursite.com and the other half to yoursite.com would it matter?.. You bet it would!

By signalling browsers and search engines to redirect all requests to one or the other you combine the popularity of both into a single address. After reading Cookie Overload it should be clear that the smart choice is www.yourdomain.com.

Not sure it's the right choice?

Navigate to http:whitehouse.gov and look at the address bar of your browser. You will see that you have been redirected to https://www.whitehouse.gov. Needing all the help it can get in search engine rankings the Whitehouse hired a team of SEO experts who came up with this.

So how do I do it?.. read on!

Testing

Before going any further, lets test to see how much of a problem it is. In the Google search bar type in the following, substituting your own domain name for 'example.com'.

site:example.com

Note at the top of the listings the summary

About 132,000 results (0.48 seconds)

Now try WWW

site:www.example.com
About 103,000 results (0.42 seconds)

An almost even split.

Redirecting to WWW

When a browser or a search engine makes a request for a document to a server, the server's first response will be numeric code indicating the success of the request. These are called HTTP Response Codes and among the possibilities are these:

200 Ok - the requested document follows
403 Forbidden - password required
404 Not Found - no such document here
301 Moved Permanently - new address follows

Except for the 404 which I'm sure everyone has seen, you've probably not given these response codes much thought. The one that we are interested in here is the 301 Moved Permanently. Search engines will follow the address to the new location while making note of the new location and changing their listings (in some future update).

An easy way to accomplish this is using .htaccess and mod-rewrite which is probably already up and running on your Apache server. Either create a new .htaccess in the root directory of your web site or add this to the existing .htaccess.

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

If you are using Drupal you are blessed because Drupal's .htaccess already has the code, all you have to do is un-comment the appropriate lines to make your choice (www or not). The code looks like this.

#.. at around line #85
#
# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# uncomment the following:
# RewriteCond %{HTTP_HOST} .
# RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment the following:
# RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
# RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]

By removing the comment indicatore # in front of the top 3 RewriteCond lines you have solved the problem.

# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# uncomment the following:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#

After saving the changed file your actions will have immediate effect.

Congratulations, wait a few weeks and run the test again to see the results. We hope you will notice a significant change in your search engine rankings and the efficiency of any services you may be running.

NOTE

The numbers in the test above were taken by running the test on whitehouse.gov and www.whitehouse.gov. From the numbers it appears that it was not long ago the Whitehouse decided to make the change. It will be interesting to watch the changes over time.

Tags: