Guest Article: Hiding ugly affiliate links using redirects

Prompted from a discussion in the forums about working with bad URL’s from certain affiliate programs we have a guest article from Harvey Kane a local SEO Consultant;

Hiding ugly Affiliate links using redirects

At some point in your affiliate career, you will invariably come across affiliate links that look a little bit too much like affiliate links. And while there’s a percentage of the population who will click on almost anything, some people won’t be so inclined to click an affiliate link.

There are a number of methods out there for working around this problem, but by far the most common method is to use an intermediary redirect script. I wanted to talk about how to do this properly, and also provide some example code for PHP.

Getting started
First, we need an affiliate link that we will be redirecting to. Let’s use a real affiliate link as an example, this way you are able to click all the example links and see them in action. This link is for Webdrive, whom I host my website with – http://www.webdrive.co.nz/?REF=HAR612 (yep, looks pretty much like an affiliate link).

Instead of linking to Webdrive directly, we want link to an intermediary page with a less affiliate-looking URL. Such as http://www.ragepank.com/webdrive/ (if you click the link it will redirect you to Webdrive).
It is up to you to choose a format for your intermediary redirect page, and make sure it is configured to redirect correctly. I’ll discuss a few ways of doing this below.

Subdomains
You will sometimes see affiliates using subdomains for their affiliate links – eg http://webdrive.ragepank.com – these look a little more official, and if you are lucky, your web host will let you setup the redirect via their control panel (no code required). If you can setup subdomain redirects via your web host, I would recommend using this method.

Easy Redirect Screenshot

If your web host allows, this is the easiest way to setup a redirect.

Domains
Funnily enough, I was digging around one afternoon and noticed that web-drive.co.nz was available (note the dash). I grabbed it, and setup a redirect sending all traffic to my affiliate link. I figured a few affiliate signups would easily cover the domain registration costs. I’m not a lawyer, but I don’t believe this is cybersquatting – and you could argue that I’m doing them a favour (I’m trying to drive more traffic to their site right?). However, you can understand if merchants don’t see the funny side of this approach. I was contacted by Webdrive’s managing director a few weeks later, and because I’m a mature adult, I handed the domain over without any fuss.
Needless to say, I wouldn’t entirely recommend this approach.

Regular redirects
The normal way of doing a redirect is to setup a script on your own hosting account. You have full control over the how you want the URLs to look, but in my experience it’s best to keep them simple and obvious. If you only have a handful of redirects, it’s easy enough to edit them manually, otherwise you can store the redirects in a database to make management simpler (which is what I do).

Redirect using PHP
If your web hosting supports PHP, then this is the most reliable way of doing redirects, and won’t give you too much grief getting them setup. However, the resulting URLs aren’t quire as nice looking as they can be.

Create a new file in the root of your website with the following code…

<?php
/* array of all affiliate links you need */
$redirects = array(
‘webdrive’ => ‘http://www.webdrive.co.nz/?REF=HAR612’,
‘example’ => ‘http://www.example.com?aff_id=1235’,
);
/* if the specified ID is in our list, do the redirect */
foreach ($redirects as $id => $destination) {
if (isset($_GET[$id])) redirect($destination);
}

/* general-purpose redirect function */
function redirect($url, $type=301) {
if ($type == 301) header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: $url”);
echo ‘This page has moved to <a href=”‘.$url.'”>’.$url.'</a>’;
exit();
}

/* if there is no match, issue a ‘not found’ header */
header(“HTTP/1.0 404 Not Found”);
echo ‘This page could not be found’;
exit;

Edit the $redirects array (adding extra lines if you need to) to reflect all the redirects that you need.
Then, link to www.ragepank.com/r.php?webdrive (replace ragepank.com with your own domain).

This redirect should now work – minimum fuss, and unlikely to run into any compatibility issues on most web hosting providers.

.htaccess method
The above method is great because it’s simple and reliable. But if you are looking for a URL that looks more like http://www.ragepank.com/webdrive/ (which I consider easier on the eye) you will want to look at the .htaccess method instead. This will only work for Apache based websites, and the Apache extension mod_rewrite needs to be enabled – ask your web host if in doubt. There are similar methods for IIS and other web servers, though I’m not going into the details in this article.

First, get the above PHP method working. The .htaccess method builds on this code.

Then, look in the root of your website for a file named .htaccess – if this doesn’t exist, create it. Otherwise, open it up for editing.

Add the following code into .htaccess

RewriteEngine On
RewriteRule ^(webdrive)/?$ r.php?$1

Note that “RewriteEngine On” may already be in your .htaccess file – if this is the case, no need to add it a second time.

To add additional redirects, copy the line containing “webdrive” and replace with the URL you want to use. If you want your link to be http://www.example.com/fishpond/ then the code would be:
RewriteRule ^(fishpond)/?$ r.php?$1

Simply use a new line for each redirect you need to setup. It’s worth noting that the .htaccess method will slow down your website if you have too many redirects in the list. If you find yourself needing more than about 50 redirects, it’s probably time to look for a different solution. If you only need a few redirects, then you won’t notice any difference in performance.

It’s possible you will get a “500 Internal Server Error” at this stage. Generally, this means your web host doesn’t allow this code to be run in .htaccess, so at this stage I would contact their support team and ask for assistance.

The poor man’s method
If the .htaccess method gives you trouble, and you only need a couple of redirects setup, you can always do it the old-fashioned way.

Create a new folder within your website, called “webdrive” (or whatever you want the link to be). Inside the folder, create an index.php file, and place the following code inside:

<?php
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: http://www.webdrive.co.nz/?REF=HAR612”);
exit;

Simply change the Affiliate link to whatever you need it to be, and that’s all the configuration needed. You will need to repeat this process for each redirect you want to create. It’s not the most technically elegant solution, but it works, and it’s easy.

All of the redirect methods mentioned here are good ways of masking the affiliate links, and these techniques are commonly used by many affiliates.

Harvey Kane is an SEO consultant, who blogs at www.ragepank.com

Thanks to Harvey for the guest article, it gives a good summary of options that most affiliates will take some time to get through while they’re building up their repotoire of code.

One thought on “Guest Article: Hiding ugly affiliate links using redirects

  1. Thanks for the helpful post. I have been looking for a why to hide ugly links. I look forward to reading more from you in the future.

Leave a Reply

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