Redirect from domain.com to www.domain.com

You may have heard that Google penalizes websites for duplicate content. What does that mean? It’s simple: if your text shows up on more than one website, Google flags that as a duplicate and won’t give your content much attention. But guess what? From the search engines point of view, those 4 addresses are 4 different websites:

  • http://www.fasterwordpress.com
  • http://fasterwordpress.com
  • https://www.fasterwordpress.com
  • https://fasterwordpress.com

Do you see the problem now?

If all those addresses point to the same WordPress setup, they will lead to the same landing page, and you just got yourself 4 copies of your content.

Don’t panic just yet!

First of all, Google is not stupid. While those 4 are technically a different addresses, it’s a common issue, so this alone won’t put your website into a blacklist of some sort.

Second, WordPress have a primary address which will be used in menus, media file URLs, RSS feeds and in a lot of other places. Which means, that even if user or search engine ended up on the “wrong” page, all links from that page will lead to the correct one with your default URL, giving that variation of your website’s address a priority.

So, are we good then?

I think it’s still a good idea to fix this issue for the sake of consistency, as it will ensure all inbound links use correct address and there is no confusion for your visitors and web crawlers.

Just follow those simple steps:

1. Make a decision which URL you want to use.

So, will it be with or without www? It does not really matter and it’s your preference.

My take on that: people are used to www.domain.com format, so when they see www, they identify it with website address (so, it’s better for printed media, car stickers, etc). If you have a redirect setup, it will redirect them to the correct address, but: that means that browser will have to send another request, which translates to a little longer wait time. So, I usually go with www version.

2. Check and update your WordPress default URL.

Login to your WordPress administrator’s dashboard and open Settings -> General menu. There, check WordPress address URL (and usually it is the same as Site Address URL, so you may need to update both. Enter  your preferred address and save.

Main-WordPress-URL

3. Setup a redirect from secondary addresses to your main address.

Now it get’s a bit technical.

Some hosting providers offer to set it up for you, so you may see that option in your hosting control panel.

But for the most websites running on Apache web server, you need to update .htaccess file. That file is located in the main directory of your WordPress setup, you can open it with FTP or File Manager of your hosting provider.

Normally, you will see something like this:


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ -[L]RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php[L]</IfModule>

Those are redirect rules to make your permalinks work.

All we need to do is to add an additional redirect, like this:


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com$[NC]RewriteRule ^(.*)$ http://www.domain.com/$1[R=301,L]
RewriteRule ^index\.php$ -[L]RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php[L]</IfModule>

4. Test

This code is to setup redirect from domain.com to www.domain.com.
Save new .htaccess file and test to make sure redirect works. It should redirect any URL on your website to the same address on the desired domain name, so domain.com/blog should go to www.domain.com/blog (not just home page).

You are done!

FAQ

Question: When I use the Fetch as Google tool in Webmaster tools, I always get a message that shows redirecting.

Answer: This is perfectly normal, and that’s exactly what should be happening. When we use redirect, web server will tell google that the site “Moved Permanently”, which actually tells Google to update all references and use new address. So, we basically redirect all SEO juice to the new address. It’s important to check that you actually have 301 Moved permanently type of redirect (as opposed to 302 Moved Temporarily). To do that, click on the Redirected status in Search Console and confirm that it uses 301 redirect. See the screenshots below:

Fetch page as Google

 

Google-Redirected-Status

Verify StatusGoogle-Redirected-Status-Check

 

Facebooktwitterredditlinkedinmail