A recurring question among website owners is whether to choose non-www or www URLs. This page provides some advice on what's best.
In an HTTP URL, the first substring that follows the initial
https:// is called the domain name. This domain name is hosted on a server where the document resides.
A server isn't necessarily a physical machine: several servers can reside on the same physical machine. Or, one server can be handled by several machines, cooperating to produce the answer or balancing the load of the requests between them. The key point is that semantically one domain name represents one single server.
So, choose one of your domains as your canonical one! There are two techniques below to allow the non-canonical domain to work still.
There are different ways to choose which website is canonical.
In this case, you need to configure the server receiving the HTTP requests (which is most likely the same for www and non-www URLs) to respond with an adequate HTTP
301 response to any request to the non-canonical domain. This will redirect the browser trying to access the non-canonical URLs to their canonical equivalent. For example, if you've chosen to use non-www URLs as the canonical type, you should redirect all www URLs to their equivalent URL without the www.
http://www.example.org/whaddup(when the canonical domain is example.org)
301with the header
The HTML5 boilerplate project has an example on how to configure an Apache server to redirect one domain to the other.
It is possible to add a special HTML
<link> element to a page to indicate what the canonical address of a page is. This has no impact on the human reader of the page, but tells search engine crawlers where the page actually lives. This way, search engines don't index the same page several times, potentially leading to it being considered as duplicate content or spam, and even removing or lowering your page from the search engine result pages.
When adding such a tag, you serve the same content for both domains, telling search engines which URL is canonical. In the previous example,
http://www.example.org/whaddup would serve the same content as
http://example.org/whaddup, but with an additional
<link> element in the head:
<link href="http://example.org/whaddup" rel="canonical">
Unlike the previous case, browser history will consider non-www and www URLs as independent entries.
With these techniques, you can configure your server to respond correctly for both, the www-prefixed and the non-www-prefixed domains. It is good advice to do this since you can't predict which URL users will type in their browser's URL bar. It is a matter of choosing which type you want to use as your canonical location, then redirecting the other type to it.
This is a very subjective topic it could be considered a bikeshedding issue. If you wish to read deeper, please see some of the many articles on the subject.
© 2005–2020 Mozilla and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.