Please note, this is a STATIC archive of website teamtutorials.com from July 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.

Click Here to Turn Your Development Passion into a Real Career.

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:

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

actually redirects you to the real url:

https://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 https://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!

24 thoughts on “How To Redirect Affiliate Links”

  1. I tried your tutorial on my website, but it did not work. I understand about the separate .php file, and that works without a hitch. But where things get messy is utilizing the .htaccess file in order to redirect a search engine friendly url to the actual .php page. The steps you gave do not work for me. I’ve tried a couple different variations, but have not had luck. It seems as though it is not able to transition from the search engine friendly url to the .php url.

  2. A few people are having problems with this. I do not use this method on my blog because I have other .htaccess mods and I am not a .htaccess expert. I do know that this does work on my scholarshiphunter.info website.

    For this website (teamtutorials) I simply created a folder. In that folder a create a folder for each offer. Then a just create an index.php file that is just one redirect. So the url for copeac would be https://www.teamtutorials.com/go/copeac/ . This is the easiest way that you can redirect with clean url’s.

    The code for the index file is simple. Just have an opening and closing php tag with a header statement i will try to paste it:

    < ?php header("location:https://affiliates.copeac.com/signup/4958"); ?>

    Hope that will solve some of the problems guys.

  3. Did you notice that you misspelled “affiliate” as “affliate”? The Scholarship Hunter site misspells it right in the picture you’ve shown here. Team Tutorials misspells it in the sidebar link for Copeac.

    Just thought you might want to know 🙂

  4. Does this drop cookies or effect them in anyway? I use the simple php header redirect as stated in a comment here and since implementation my sales have really dropped. Worried its blocking cookies somehow!?

  5. Hi, nice approach using .htaccess to give a nice url name without the .php extension. Alternative than RewriteEngine, I use:

    SetHandler application/x-httpd-php
    ForceType application/x-httpd-php

    Hope it helps.

    For other approach of redirection method that does not require .htaccess modification, I just build a site that does that. Hope you might take a look. 😉

  6. I do not understand this part:

    [Add the following lines of code:

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

    Where do we add these lines of code to? Do we copy the exact lines?

  7. I have problem with the 2nd part, where you have to edit .htaccess to make the link look clean. I copied the exact same code but it did not work for me : (

    Any guidance?

  8. @Ron

    Ron in order for the mod rewrite to work, you would have to have the .htaccess in a folder and that folder would also need to contain link.php. It is hard to troubleshoot without seeing how your links are structure. Feel free to fill out the contact form to email us if you want some additional help.

  9. Hey thanks for this simple yet effective strategy! I quickly implemented this on a couple of my blogs. Is there any way to 100% mask the referrer id?

  10. Hello John,
    I enjoyed your tutorial but my need has a twist…
    My site is setup to support hundreds of affiliate links stored in a MySQL database. I pull the links with a recordset into a repeat region as well as with a dynamic list/menu (using Dreamweaver & PHP). Each link is stored in it’s own record along with affiliate name, etc.
    Any suggestions how to modify what you outlined in the tutorial.
    Thx,
    Dave

Comments are closed.