Coding

Protecting Outgoing Links

Sometimes with your website you want to protect your links a little. I’ve previously written about how paid links destroyed my blogs¬†and with this blog I want to prevent that from happening.

Careful Linking

A little background

The common way of looking at links from your site to another site is that search engines such as Google see these as “votes” for the other site. The more votes you receive from sites which themselves have more votes (and that keeps on going) then the higher up the search engine rankings you move.

However, people cottoned on to this and created spam links. There is also a theory that search engines don’t like affiliate links. Another theory is how bad “site wide” links are whereby every page links out to a given site.

Prevent any damage

So there’s a risk of damaging your site if you are using these site wide links, both for you and the site the links are pointing at. So I’m employing a simple 2-stage process to make sure that the search engines know that I want them to ignore most outgoing links.

rel=”nofollow”

The first is simply to add the above to any and every link that you don’t want the search engines to follow. It’s written quite easily as follows:

<a href=”http://www.13weekchallenge.co.uk” rel=”nofollow”>13 Week Challenge</a>

Simple. Search engines see that and should then ignore the link.

Redirect and ROBOTS.TXT file.

The next one is a bit more complicated to set up, but also gives other benefits. I created a folder simply called /redirects. I then use a special file called “robots.txt” to again tell search engines to ignore this folder. The content of this folder then becomes:

User-agent: *
Disallow: /redirects/

Just drop those lines into a file called “robots.txt” and upload it to your root directory (the same one in which your main index.php is stored).

Test the robots.txt file

It’s well worth testing this file. Get it wrong and you could actually block the entire website from Google and all other search engines! If you haven’t already done so, sign up to the free Google Webmaster Tools and add your site.

Then go to crawl, robots.txt Tester. Paste in your code (assuming you are testing new code and not the one it’s found) and then type in a few URLs. your index.php file should be allowed, whereas when you type in a blocked directory (and remember to include the trailing ‘/’) it should be blocked.

A bonus point here

Whilst you are editing the robots.txt file it’s well worth adding the wp-admin file – you don’t want search engines listing that:

User-agent: *
Disallow: /redirects/
Disallow: /wp-admin/

Redirect from that redirects folder

And finally a bit of coding that holds this all together. It’s very easy. Just open up notepad, drop in and amend the following code and then save it as [name].php:

<?php
header(“Location: http://www.13weekchallenge.co.uk”);
?>

Apply the redirect

Now it’s very easy to link this all together. The link out in your blog post changes from what I had above to:

<a href=”http://www.13weekchallenge.co.uk/redirects/[name].php” rel=”nofollow”>13 Week Challenge</a>

Belt and braces – tell search engines not to follow the link and tell them not to look at the file that you are linking to.

Another quick bonus

There’s now also another quick win bonus. If you have linked to an affiliate site, e.g. XYZ Widgets and created a redirect called xyzwidgets.php you have all of the above working. But if you later on mention them in a blog post you can now link straight to your redirect page. You don’t need to dig out their latest affiliate link – the information is already saved in the code and you just link to the standard page.

Also, should that merchant end their affiliate scheme or move it to another provider, then you only need to change the link in the one file.

Yet another bonus is available

How many times are people clicking on your links? Well if you have server logs you will see or if you want to be really clever and have simple mysql knowledge then it’s not difficult to add to the redirect script a simple counter so that you can see how many times it has been clicked on.

And, guess what…

On top of this we get yet another bonus. If you use this for all of your outgoing links you get a lot of control over them. Search engines hate sites which link to 404 (Not found) pages. So if you are linking to a third party and they remove the page you put yourself at risk of pointing to a 404 page.

This way you are pointing to a page that you maintain. The redirect handles the jump to the third party page so there’s less to check, less to maintain and if you do miss one then search engines shouldn’t notice and therefore won’t punish you.

Please follow and like us: