Protect your site

A few years back when you owned two domains for a web site, for example the .com and .co.uk version of a domain, you would more than often just 'mirror' or 'park' one domain on the other. Then when you went to either domain you would see the identical site and therefore not lose any visitors to either domain. This was standard practice and still often is. The option to park a domain is available from almost every hosting panel. However with its abuse by black hat SEOs it's beginning to cause some site owners a problem. There is another problem too that's been around for over a year - URL Canonicalisation, as explained in a direct quote from Matt Cutts:

Q: What is a canonical url? Do you have to use such a weird word, anyway?
A: Sorry that it’s a strange word; that’s what we call it around Google. Canonicalization is the process of picking the best url when there are several choices, and it usually refers to home pages. For example, most people would consider these the same urls:

* www.example.com
* example.com/
* www.example.com/index.html
* example.com/index.html

But technically all of these urls are different. A web server could return completely different content for all the urls above. When Google “canonicalizes” a url, we try to pick the url that seems like the best representative from that set.

The problem Google, and other search engines have is that they're not always able to just select one version and so indexes two or more versions. This is where the problems can happen. Let's say you market your domain using the www version of it. But then some malicious person decides to sabotage your rankings by simply dropping a load of links to the non www version of your site. You can kiss goodbye to your Google rankings if Google's algo picks this up. Yes it has happened and still is from what I've read. The best thread I've seen about it was on Threadwatch.

So how to fix these two issues. Well there are solutions using either htaccess (on Apache servers) or PHP. To control any parked domains, choose the one you want to use and stick with it. Only use that one for internal links. Below is an excerpt from the htaccess file that I have running for my Web Developer Kit. I originally set this site up under designware.co.uk, but since bought the webdeveloperkit.co.uk and .com domains and decided to run the site under the UK domain instead.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*\.webdeveloperkit\.com
RewriteRule (.*) http://www.webdeveloperkit.co.uk/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^.*\.designware\.co\.uk
RewriteRule (.*) http://www.webdeveloperkit.co.uk/$1 [R=301,L]

The above pretty much says that if the old domain eg. webdeveloperkit.com is used to get to the site, be it the www or non www version, then do a 301 redirect to http://www.webdeveloperkit.co.uk. The /$1 also says that keep any appended page address from the original, this way people are not redirected to your front page but the respective page that the visitor was going to, but on the correct domain. The website is question was originally set up on the designware.co.uk domain and the other domains are parked on top but this method works perfectly fine.

To save your site from sabotage then you need to make the non www version of the domain redirect as a 301 to the www version (or vice versa if you don't want the www version indexed). This is another Rewrite rule using:

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

Of course not everyone has htaccess available to them so for a PHP method I've taken this from the Threadwatch page. It's untested but I intend to use it this weekend on a site running PHP but on a Windows IIS server:

< ?php if ($_SERVER['HTTP_HOST'] != "www.webdeveloperkit.co.uk") {
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.webdeveloperkit.co.uk".$_SERVER['REQUEST_URI']);
exit;
}
// your usual page code can go here
? >

If you have the problem where you have both the raw domain address and then say index.html both indexed then this will be seen as two duplicate pages. Again this could cause an issue to have two identical pages indexed which is again unfortunate as plenty of people have say print versions of pages, I know my older domains have both index.htm and index.html, another method from the 'old days' of web development. However these tricks need fixing to ensure the safety of your rankings. So with htaccess you can use:

RewriteRule ^index\.htm$ http://www.webdeveloperkit.co.uk [R=301,L]
RewriteRule ^index\.html$ http://www.webdeveloperkit.co.uk [R=301,L]

With thanks to Khalid for the help with htaccess.

  1. One Response to “Protect your site”

  2. For anyone who wants the ASP version, kindly provided by Mick

    < %
    if request.servervariables("HTTP_HOST") <> "www.domain.com" then
    response.status = "301 Moved Permanently"
    response.addheader "Location", "http://www.domain.com"
    end if
    %>

    By Sarah on Nov 17, 2006

Post a Comment

Please use your real name, nickname or an online name. Names I consider spam will be changed.