Best way to hide and cloak your affiliate links?

by Yang Yang on September 19, 2009

One may first think of using JavaScript to do this by dynamically changing the windows status bar URL, but unfortunately this trick doesn’t work across Firefox browsers.

The truth is the visitor or clicker will eventually find out that they’ve been referred to the affiliate merchant by you from the ultimate landing URL – sometimes this may be totally redirected to the clean home page of the merchant, but many’s the time it’s not.

So the one thing you can make sure is the reader of your site must click through your affiliate link to get to the merchant. And the following snippet will help you achieve this. Start a index.php file and put this in:

<?php
header("Location: http://www.example.com/referral.php?aff=12345");
?>

In which http://www.example.com/referral.php?aff=12345 is your referral link. Save this file somewhere in your domain such as /go/example. The next time you want hide and cloak the real affiliate URL, or at least make it look more neat, just point your readers to /go/example and they will be automatically redirected to the affiliate link.

Another good way – via Javascript, to hide or cloak the status bar URL

Another way of doing this is to rely on JavaScript for changing the href property of the a tag when the visitor clicks on the affliate link:

<a onclick="javascript:document.location='http://www.example.com/referral.php?aff=12345';return false;" rel="nofollow" href="http://www.example.com">Example</a>

The potential problem of this approach is that if the visitor browser’s Javascript capabilities are turned off, you will not be credited for your referral because they will be using the plain href link.

Subscribe to Kavoir: blog feed

You should also read:

df October 13, 2009 at 10:07 am
Yang Yang October 17, 2009 at 7:09 pm

Wow, that’s a much much more sneaky solution!

But kind of unethical because that’s deceiving the readers. ;)

Yang Yang January 26, 2010 at 1:39 pm

It’s gone!

Elle November 2, 2009 at 10:27 am

So I have tried adding a php file as well as certain cloaking plugins and they work so-so, however what if you have multiple affiliate programs/product links what do you recommend? Making multiple php files seems not to be the best answer?? Wondering if there is an easier way that is just as clean? Thanks :)

Yang Yang January 26, 2010 at 1:34 pm

It’s certainly possible but involves a little more code that’s slightly more complex.

Jonathan August 29, 2010 at 9:37 pm

You should be able to support multiple affiliate links by creating one directory with one PHP file.

Here is how you can do it.

You will need to be using an Apache server with mod_rewrite enabled for this to work. You will also need to be able to alter Apache settings with an htaccess file.

First, create your directory. Call it “go”.

Next, within this directory, save a new .htaccess file. The file contents are as follows:


Options +FollowSymlinksRewriteEngine on
RewriteRule ^([a-z0-9_-]+)$ index.php?token=$1 [L,NC]

These settings will allow you to use a URL such as /go/amazon, and it will be rewritten to index.php as index.php?token=amazon.

Next, in your index.php file, you can add multiple redirects based on the token which is passed in. Example:


<?php

switch ( $_REQUEST['token'] ) {
case 'amazon':
$redirect = 'http://www.amazon.com?affid=1';
break;
case 'amazon2':
$redirect = 'http://www.amazon.com?affid=2';
break;
}

if ( isset($redirect) ) {
header("Location: {$redirect}");
} else {
header("HTTP/1.0 404 Not Found");
}

Just place a “token” at the end of the URL (eg. /go/token). Then make sure there is a case statement for it (case ‘token’:), and set $redirect to the real affiliate link (surrounded by single quotes).

Yang Yang September 18, 2010 at 2:23 pm

Thanks, Jonathan! That’s a nice contribution!

Slavi September 17, 2010 at 12:27 pm

you could also use onmouseover of the “a” and change the status of the link

I think it is a good idea to use your own redirect script in case you have to change your aff ID for some reason

Yang Yang September 18, 2010 at 2:24 pm

Yeah that would do. I use my affiliate id on many sites so if I could use a redirect script, when my affiliate id or the merchant affiliate structure changes, all I have to is to make one change and it’s all fixed.

Comments on this entry are closed.

{ 1 trackback }

Previous post:

Next post: