WWW vs non-WWW Domain Names

Wed, Nov 4, 2009 3-minute read

A fairly common website optimization that a lot of web 2.0 dot com companies are doing is to remove the leading www from the domain name. Removing the legacy www leaves you with a domain like https://nginx.org/. Ok so Nginx has a modern domain name but should you switch also?

Reasons for non-WWW

First, the domain name is more concise, easier to remember and just looks better. One caveat: you will need to setup a 301 redirect for requests with the three w’s to go to the non www version (see below).

Hold on, is it that simple?

No, it’s not, there are some disadvantages to having a domain name without a leading www.

Cookies are stored in a web browser at a set domain name. If you are not using the www, the cookie is saved to root: example.com. This can be quite a large disadvantage because the cookie is then passed along for every single request that browser makes for any subdomain on example.com. Even if you setup an alternate server just for serving images (images.example.com), your users browser will sent the cookie to that domain while fetching images. Sure its not a lot, but it does add up and removes some flexibility from your setup.

Another area it impacts is a site specific search in google. Doing a google search like the following: managing complexity site:markdeepwell.com, will not only search your main example.com website, but also all its sub-domains.

Reasons for WWW

Just about every person on the planet can recognize a domain name if it starts with www.something. Yes the www is redundant and not needed anymore, but it is a bit more user friendly.

If your site has multiple sub-domains, then I’d definitely recommend you go with a www domain to keep them all separate. Large websites benefit more from having the leading www; alternatively, if you have an extremely simple website like upcomingholiday.com it would do no harm to remove the www.

If you have a domain that’s been around for a few years it is possible to switch from one to the other, as long as you setup 301 redirects for SEO purposes, or else your rankings will plummet.

No matter what, make sure you have a 301 redirect setup so that users only see one version of your site instead of two. Be consistent by picking one and sticking with it.

Here are some common htaccess rules for redirecting requests to the proper domain name.

Redirect www to non-www:

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

Redirect non-www to www:

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]