How To Redirect Affiliate Links

This tutorial will show you how to redirect your affiliate links using a PHP script and a simple edit to your .htaccess file. For some reason users seem to trust links more if the reside on your own server. Using a “link cloaking” technique is an easy way to increase revenue from affiliate offers.

For this tutorial we will use the website www.scholarshiphunter.info for example. On the left navigation menu you will see an affiliate section.
How To Redirect Affiliate Links

If you mouse over you will notice that the link goes to a folder on the site called links.
How To Redirect Affiliate Links

Really, the folder /links doesn’t exists. We modify the .htaccess file to redirect the requests for the url /links to a script called link.php. So for example:

http://www.scholarshiphunter.info/link/efinance-loans

actually redirects you to the real url:

http://www.scholarshiphunter.info/link.php?id=efinance-loans

It may sound difficult, but it is really very simple. First create the PHP file that will redirect the links to the appropriate affiliate offers. You can do this in notepad if you don’t have an editor of choice, however I will use Dreamweaver because I like the way it colors the code.
How To Redirect Affiliate Links

Basically the only things that you need to change are the link variable and the affiliate link. The link variable is the “folder” that you want the link to be sent to on your server. The affiliate id is the affiliate link provided by your affiliate company. The bottom section of code simply gets the id variable from the browsers and redirects you to the affiliate offer, using a header redirect.

Here is the exact PHP code used on scholarshiphunter.info:
How To Redirect Affiliate Links

Create to file, replacing the variable and the afflaite links with your own, and save it as link.php. Upload this file to the root of your web directory on your server. Just remember that when you edit the file, do not include a comma on the last affiliate link offer.

How To Redirect Affiliate Links

Once you have the link.php file uploaded you could simple link to it. So if my keyword was coolstuff, the link would be http://www.scholarshiphunter.info/link.php?id=coolstuff . However, we will redirect the request using .htaccess to make the files appear to be in folders on the server. Log into your server via ftp and edit the .htaccess file. Add the following lines of code:

RewriteEngine On
RewriteRule ^link/([/_0-9a-zA-Z-]+)$ link.php?id=$1

That code simply tells the server to rewrite any url that is calls the folder /links/yourvariablehere to the real link.php?id=yourvariblehere. This all happens in the background so the users sees the /links/yourvariblehere link.

It is that simple. Now all you have to do is add the affiliate links to your page. Here is what the links look like on scholarshiphunter.info:

How To Redirect Affiliate Links

It is really that easy, now go make some money!