WWW Redirect

From Seobility Wiki
Revision as of 15:55, 21 February 2019 by Techteam (talk | contribs)

Jump to: navigation, search

Basic problem

Figure: WWW Redirect - Author: Seobility - License: CC BY-SA 4.0

For most users it is not of particular importance whether they access a website via a www or a non-www link. However, the fact that a website is accessible with or without the input of “www” can seriously impact on a website's search engine ranking.

When a URL is written in two different ways (www and non-www) it means the same website appears online under two different domains. This then leads to internal duplicate content, making it harder for Googlebot to find the page most relevant for a particular search term and to index it correctly. In addition, Google interprets links that actually refer to the same website (but once with and once without www) as links to separate pages, which distributes the link power between the www and the non-www domain. Thus, both domains rank worse than would be the case if the link power were bundled on one variant of the website.

Apart from its relevance for search engine optimization, the choice of a preferred domain (www or non-www) is also part of a clean technical setup of a website and therefore mandatory for every webmaster.

Possible solutions

If a website is accessible with both a www and a non-www link, a 301 redirect to the preferred domain should always be set up. The HTTP status code 301 - moved permanently - indicates to browsers that a requested file has been permanently moved to a different URL and that the entered URL is no longer valid.

One option, when using the Apache web server, is to set up the redirect by using a .htaccess file. For example, to redirect the URL example.com to the URL www.example.com, save the following source code as a .htaccess file or insert it into an existing .htaccess file:

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

If you want to redirect to the version without www instead, the URL must be inserted without www.

Another simpler option that delivers the same results is to create a redirect via a vHost configuration:

<VirtualHost *:80>
: ServerName example.com
: Redirect permanent / http://www.example.com/
</VirtualHost>

<VirtualHost *:80>
: ServerName www.example.com
: # real server configuration
</VirtualHost>

Apart from setting up a 301 redirect, you should always set your preferred domain in Google Search Console (under Site Settings → "Preferred domain"). This ensures that Google always uses your preferred domain choice for future crawling and indexing. In addition, Google automatically follows links referring to example.com as if they were pointing to www.example.com. Setting your preferred domain in Google Search Console is thus a useful addition to the 301 redirect.

Alternatively, the problem of duplicate content can be addressed by using a canonical link that specifies the preferred (or canonical) URL. In this way, search engines know which domain should be indexed and displayed in search results. However, users are not redirected to the correct website version. For this reason, using a canonical link is less suitable for solving the problem at hand.

More tips

An important point to remember when setting up a 301-redirect is to ensure that not just the homepage but all subpages are redirected to the correct domain. Further, you should take into account the different network protocols (http and https) when setting up a redirect, as these can also cause duplicate content issues. For example, https://example.com, http://example.com and http://www.example.com should all be redirected to https://www.example.com.

Related links