WWW Redirect

From Seobility Wiki
Jump to: navigation, search

Basic problem

WWW redirect
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 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 an .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.

With the free Seobility Redirect Checker, you can easily analyze if the redirects on your website are set up correctly.

In summary: WWW Redirect FAQs

Why do you need a www redirect?

If a website can be accessed both with and without entering “www”, this leads to internal duplicate content and consequently, Google does not know which of the URLs should be ranked in the search results.

What are possible solutions if a website is accessible both with and without www?

You should always set up a 301 redirect which redirects website visitors and crawlers to your preferred URL variant.

How to set up a 301 redirect?

Redirects can either be configured via a .htaccess file or via a vHost configuration.

What should you keep in mind when setting up a 301 redirect?

When configuring the 301 redirect, you should make sure that all sub-pages (and not just your homepage) redirect to the correct domain. In addition, the different network protocols should also be considered.

Related links

Related articles


About the author
Seobility S
The Seobility Wiki team consists of seasoned SEOs, digital marketing professionals, and business experts with combined hands-on experience in SEO, online marketing and web development. All our articles went through a multi-level editorial process to provide you with the best possible quality and truly helpful information. Learn more about the people behind the Seobility Wiki.