One 301 Rewrite to Rule Them All

One Killer Mod Rewrite RuleWe do a lot of SEO Audits here at Bowler Hat and often many of the sites we work with have multiple URLs attached to them and have multiple URLs indexed. This is problematic for many reasons with the primary one being a potential penalty due to duplication but more often you will see equity split over several different domains or subdomains. We all want links to our sites but if have 10 links to one site and 10 links to another then you are failing to pool all of your inbound link equity into the one single domain.

Luckily, there is a simple solution to this using the ever powerful mod rewrite tool that can redirect all of your many domain variations to the one single domain that you intend the site to run on.

Editing Your Htaccess file

 

To achieve this and redirect all of the many domains your site runs on you simply need to add the following to your htaccess file.

RewriteCond %{HTTP_HOST} !^www.yoursite.co.uk
RewriteRule (.*) http://www.yoursite.co.uk/$1 [R=permanent,QSA,L]

 

Note: replace yoursite.co.uk with your primary domain! 

 

What is this doing?

In a nutshell, this is looking to see if the first URL give is not equal to (!) your URL. If that is the case then it specifies that the URL should be redirected to the correct version with anything after the / maintained.

 

Do you need this?

 

In most cases, this won’t hurt for all sites but let me give you an overview of the potential issues and how you can test for this.

 

www and non-www

The first problem we see is that sites are often indexed with the www and non-www version so we will see:

http://bowlerhat.co.uk
http://www.bowlerhat.co.uk

To test for this simply go to Google and use the site operator:

site:bowlerhat.co.uk
site:www.bowlerhat.co.uk

 

If I do this I should only see results for the www version which in the case of my own site I do (you would hope so wouldn’t you, given what I do for a living).

 

Multiple Domains on one site

In the annals of SEO it must have got banded around somewhere that having multiple URLs of the-keywords-I-want-to-rank-for.com was a good idea. It wasn’t, but still, that does not stop people buying up and mapping several domains to a single site and we may have several domains indexed. The problem above can also stack on top of this one so we end up with:

yoursite.co.uk
www.yoursite.co.uk
another-url.co.uk
www.another-url.co.uk
yet-another-keyword-rich-url.co.uk
www.yet-another-keyword-rich-url.co.uk

 

In this instance, we may have six versions of the site indexed with equity split across six variations

There are a few ways to test and investigate this and I would first like to look at the hosting and see what domains are mapped to the site to get a definitive list. Alternatively, you can take a chunk of unique text and “wrap it up in double quotes” and search for it in Google.

 

This should return any variations with some possibly hidden behind the duplicate content message:

In order to show you the most relevant results, we have omitted some entries very similar to the 55 already displayed.
If you like, you can repeat the search with the omitted results included.

 

Site responds to any variation of the domain

This can be the worst one yet but fortunately is the easiest to test for. Some sites will answer on any variations of the subdomain so *.yourdomain.co.uk

www.yoursite.co.uk
ww.yoursite.co.uk
w.ww.yoursite.co.uk

 

Often this presents itself when someone links to your site and misses of a ‘w’ or some such so you end up with ww.yoursite.co.uk. Google then follows this link, the site does not redirect and indexes the entire site as ww.yoursite.co.uk. Now, not saying you should do this but if someone unscrupulous spotted this they could quite easily link to your site with lots of versions of the site and get many, many versions indexed and cause you further problems.

 

sex.yoursite.co.uk
drugs.yoursite.co.uk
rockandrolll.yoursite.co.uk

 

I am sure you get the picture here.

 

One 301 Rewrite to Rule them All

 

Fortunately, this one simple rewrite solves all of these potential problems and given enough time will also fix historical problems by focusing all value into the single site. The only real caveat here is if you have brought several domains and some of them have a questionable history and you should likely perform a domain audit on each one to check it’s history as a 301 can pass on the good and bad history of a domain.

 

How does it work?

 

Well, mod rewrite is magic, plain and simple, but as an overview, the first line sets a condition where we look for all request URLs that do not start with www (!^www). The second line then redirects to the www. version of the URL and passes on the full URL with everything after the slash preserved.

This essentially gives you an all in one rewrite solution across your entire site and covers all pages and all URLs – simples!

Any questions please leave a comment and remember sharing is caring. 🙂

 

 

Facebook
Twitter
LinkedIn
Pinterest

2 Responses

  1. Hi,

    I was searching for a similar topic and again came through your site 🙂 I am currently running .com version of the site and have domain only for .co.uk. Is it best to just point it from the domain setting (Web Forwarding) or create a homepage for co.uk and then redirect it to .com version of the site? I would like to have com version only.

    What is best?

    Thanks in advance.

    1. Hey Beyaz – no point to have additional hosting here. You just want both domains pointing at the main site with a 301 permanent redirect from the .co.uk to .com to ensure there are no duplication issues. Hope that helps. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Free Digital Marketing Review

Book a call with Marcus Miller to learn how to generate more traffic, leads and sales.

1. Review your current marketing
2. Identify your key opportunities
3. How to improve results & cut costs!

Put over 20 years of marketing experience to work for your business today.