Drop the “WWW”

How and why to use example.com, not www.example.com.

Four trends. One solution. Two implementations. WWW is dead; long live WWW!

Trends:

Solution:

  • Accept requests for your site with a “www.” prefix but encourage the use of your domain without that prefix.

Implementation:

There are two main ways to implement this. Each has slight advantages over the other.

  1. Redirect all requests from your http://www.example.com domain to http://www.example.com. This is the method preferred by No-WWW.org, which suggests the following .htaccess rule (for Apache servers):

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    
    • Benefit: Using this method, no one will ever end up at or link to any page on your www.example.com domain. Ever!
    • Drawback: Forcing a redirect may increase page load time ever so slightly, but only for anyone requesting a page from www.example.com. However, as noted above, there will never be any more new links to that domain (ever!), which minimizes the number of times this redirect will take place.
  2. Ensure www.example.com and example.com both go to the same content (this is a default on most hosts), but designate example.com as preferred (or “canonical”).

    • To designate the canonical version of a page accessed at http://www.example.com/products, you simply need the following line of code in your <head>, as described here:

      <link rel="canonical" href="http://example.com/products" />
      

      Generating this code is trivial in any scripting language (especially with a regular expression).

    • Optionally, make sure any internal relative links on your page go to your example.com domain even when the page was accessed from www.example.com. To do this, use the <base> tag (more information on base):

      <base href="http://example.com/" />
      

      Or simply include the domain in every link on the page, e.g. <a href="http://example.com/products">products</a>, not <a href="/products">products</a> or <a href="products">products</a>.

    • Benefit: Possibly faster initial page load time for users accessing the “www.” variant of your domain

    • Drawback: Users who accessed a page on www.example.com may create links to the “www.” variant of your site, perpetuating the usage of that domain.
    • Drawback: If you skip the <base>, it is difficult to ensure all links start with your proper domain name; while many frameworks make this easy, some raw HTML or even an AJAX call may introduce non-canonical links.

For more information on how and why to deprecate the “www.” variant of your site, see http://no-www.org.

Personally I think solution #1 is the strongest, but the choice is yours. Pursuing neither implementation is lazy and continues the trend of URLs which are longer than necessary. In other words, if you do nothing, you can’t call yourself a software artist or user-interface guru; you can call yourself a hack.


February 13th, 2009. (Updated: February 13, 2009 at 5:28pm.)
Alan Hogan (@alanhogan).  Contact · About