www and non-www URLs

A recurrent question among website owner is whether to choose non-www or www URLs. This page provides advice on what's the best to do.

You can have both

First and foremost, know that you can have both and probably should since you can't predict which URL users will type of their browser bar.

Choose one and stick with it!

The choice is yours, but if you choose one, stick with it. It will make your website appear more consistent to your users and to search engines. Sticking with one includes always linking to the chosen domain (which shouldn't be hard if you're using relative URLs in your website) and always sharing links (by email/social networks, etc.) to the same domain.

From a techincal point of view, there are different ways to choose which website is canonical.

HTTP 301 redirects

In that case, if you've chosen non-www URLs as canonical for instance, you configure the server receiving www HTTP requests (which is most likely the same) to respond with an HTTP 301 to the same URL without the www. Example:

A server receives a request for and answers with a code 301 with the header Location:

The HTML5 boilerplate project has an example on how to configure an Apache server to redirect one domain to the other

In this case, you're serving the same content for both domains and tell search engines that which URL is canonical. In the previous example, would serve the same content, but with an additional link element in the head:

<link href="" rel="canonical">

Unlike in the previous case, the browser history will consider non-www and www URLs are separated entries.

How to choose which one is the best

This is such a subjective topic that it can be considered as a bikeshed-ish issue. Feel free to read the existing pages on the web on that topic and make your own opinion.

See also

Document Tags and Contributors

Contributors to this page: dbruant, teoli, ethertank
Last updated by: teoli,