www and non-www URLs

  • Revision slug: www_vs_non-www_URLs
  • Revision title: www and non-www URLs
  • Revision id: 388839
  • Created:
  • Creator: dbruant
  • Is current revision? No
  • Comment

Revision Content

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 http://www.example.org/whaddup and answers with a code 301 with the header Location: http://example.org/whaddup.

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, http://www.example.org/whaddup would serve the same content, but with an additional link element in the head:

<link href="http://example.org/whaddup" 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

Revision Source

<p>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.</p>
<h2 id="You_can_have_both">You can have both</h2>
<p>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.</p>
<h3 id="Choose_one_and_stick_with_it!">Choose one and stick with it!</h3>
<p>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.</p>
<p>From a techincal point of view, there are different ways to choose which website is <em>canonical</em>.</p>
<h4 id="HTTP_301_redirects">HTTP 301 redirects</h4>
<p>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:</p>
<p>A server receives a request for <code>http://www.example.org/whaddup</code> and answers with a code 301 with the header <code>Location: http://example.org/whaddup</code>.</p>
<p>The<a href="https://github.com/h5bp/html5-boilerplate" title="https://github.com/h5bp/html5-boilerplate"> HTML5 boilerplate project</a> has an example on <a href="https://github.com/h5bp/html5-boilerplate/blob/7a22a33d4041c479d0962499e853501073811887/.htaccess#L219-L258" title="https://github.com/h5bp/html5-boilerplate/blob/7a22a33d4041c479d0962499e853501073811887/.htaccess#L219-L258">how to configure an Apache server to redirect one domain to the other</a></p>
<h4 id="Using_link_with_the_attirbute_rel.3D.22canonical.22">Using <a href="/en-US/docs/HTML/Element/link" title="/en-US/docs/HTML/Element/link">link</a> with the attirbute <a href="http://support.google.com/webmasters/bin/answer.py?hl=en&amp;answer=139394" title="http://support.google.com/webmasters/bin/answer.py?hl=en&amp;answer=139394">rel="canonical"</a></h4>
<p>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, <code>http://www.example.org/whaddup</code> would serve the same content, but with an additional link element in the head:</p>
<p><code>&lt;link href="http://example.org/whaddup" rel="canonical"&gt;</code></p>
<p>Unlike in the previous case, the browser history will consider non-www and www URLs are separated entries.</p>
<h2 id="How_to_choose_which_one_is_the_best">How to choose which one is the best</h2>
<p>This is such a subjective topic that it can be considered as a <a href="http://bikeshed.com/" title="http://bikeshed.com/">bikeshed</a>-ish issue. Feel free to read the existing pages on the web on that topic and make your own opinion.</p>
<h2 id="See_also">See also</h2>
<ul>
  <li><a href="http://www.chrisfinke.com/2011/07/25/what-do-people-type-in-the-address-bar/" title="http://www.chrisfinke.com/2011/07/25/what-do-people-type-in-the-address-bar/">Stats on what people type in the URL bar</a> (2011)</li>
</ul>
Revert to this revision