Canonical redirections: www vs. no-www

One of the decisions, which goes by moments, is the use of a domain with associated website and the use of www or no-www.

Surely, there will be people who tell you that for i-don’t-know-what reasons to use no-www and others that www… and although theoretically, it should not affect, since at any level we have to talk about “hostname” (that is, the entire address) there are some elements to consider.

The first of these is that when the web was invented, the domains themselves already existed, and, to differentiate the mail service, FTP or the web, the use of the www in front of the domain was proposed. So yes, websites, in theory, should carry the www according to their invention. Anyway, although this is a “it does not matter”, there are some technical elements to take into account, such as redirects.

The situation is when we have to migrate, for example, from no-www to www, considering HTTP and HTTPS; no, you can’t directly migrate everything to the final URL.

And there are current security systems, for example the HSTS, which clearly indicate how we have to make this improvement in the security of communications. There are even browsers that, if you do not do them in the correct order, could give you a message of attention.

Let’s start from the base of all these combinations:

  • http://example.com/
  • http://www.example.com/
  • https://example.com/
  • https://www.example.com/: this is what we always want to reach.

If we start with the first of them, we have to take the following steps when making the redirection:

  1. http://example.com/
  2. http://www.example.com/
  3. https://www.example.com/

We must start from the basis that you should not go from HTTP to HTTPS if the hostname does not match, so first we have to stay in the same HTTP protocol, and change the hostname, in this case from no-www to www. Now that the hostname is the same, we can upload from HTTP to HTTPS without receiving any notice.

In the second case, the route is somewhat simpler:

  1. http://www.example.com/
  2. https://www.example.com/

In this case, since the hostname is already the same, we simply have to upgrade from HTTP to HTTPS.

The third case is also quite straightforward.

  1. https://example.com/
  2. https://www.example.com/

In this case, we already have the HTTPS protocol, so there is no problem in simply modifying the hostname and passing it from no-www to www.

With this, we will achieve that the modifications of protocols and hostname are made correctly and orderly without affecting any incompatibility.


About this document

This document is regulated by the EUPL v1.2 license, published in WP SysAdmin and created by Javier Casares. Please, if you use this content in your website, your presentation or any material you distribute, remember to mention this site or its author, and having to put the material you create under EUPL license.