How to Make a Redirect for Affiliate Links

Yesterday I got an email from a friend asking how to make an affiliate link look “clean”. If this very experienced blogger was asking the question, then chances are, there are many of my readers that would like to know too.

WHY WOULD I WANT TO SET UP A REDIRECT?

When you sign up with an affiliate program, the program has to give you a unique line of code that can be tracked so that you can get proper credit for the leads or sales that you generate from your site to theirs. In most cases, this means the link you are assigned will be long and drawn out, a combination of letters, numbers and symbols, and it will be long. For many users, if they mouse over such a monstrosity, they will not even click through for fear of the unknown.

Another reason you may want to use redirects with affiliate links has to do with managing them. Let’s say you sign up as an affiliate to program XYZ and you link to your affiliate link in dozens of blog posts. Then, one day the affiliate manager changes your affiliate link. You now have to go back through all of those links and change them. However, if you had set up a redirect, you could change it in one place and all the links would be routed correctly.

HOW DO  I SET UP A REDIRECT?

Setting up a redirect is a fairly simple process.  Basically you have to create a new php file that will contain the affiliate link and some additional code, save it with a unique name, and use the new file name when referring to that affiliate link.

1. Open Notepad or your favorite code editor

2. Type in the following code as you see it below, replacing the red text with your affiliate link.

How to set up a redirect

3. Save the file as keywordxyz.php (you come up with a file name that makes sense)

4. Upload the new php file to your web server (Need help with FTP? Check out my FTP Tutorial)

5. When linking to your affiliate link, you can now use:

setting up a redirect

I find that using redirects helps me stay more organized and I don’t have to go hunting for my affiliate links everytime I want to use them.

As it is with everything in the web development world, there is usually more than one right way to do everything. There are other ways to set up redirects, but I have found this method to be the easiest to set up and keep track of.

Related articles:

RSS 2. October 2007 (08:46)
Filed under: Tutorials

19 Comments»

  1. Jimson Lee

    2. October 2007 | 10:34 h

    For techies, you can also use a .htaccess “RewriteEngine on
    RewriteRule”, an HTML redirect (for non supported PHP websites), or even a Javascript redirect.

    Different flavors for different folks.

    Does anyone know how to hide an Amazon affiliate link with a specific product? I am referring to the portion after “tag=”

    Thanks,
    Jimson

  2. Charity

    2. October 2007 | 13:43 h

    Thanks for this little tutorial Char. Just so I’m clear - I’d have to create a separate file for each affiliate redirect, yes? Or could one ideally drop the php code into just one file and call separate redirects from that? Sorry if that’s a totally noob question.

    I like the idea of using .htaccess as well, to forgo creating several redirect pages for numerous affiliates, but I’m unfortunately not very comfortable messing with my .htaccess. I’ll try the former first. :)

  3. Char

    2. October 2007 | 13:51 h

    Jimson - my Amazon links are the ones I do not tend to redirect.

    Charity - yes, I create a separate file for each affiliate.

  4. David Wilson

    2. October 2007 | 14:33 h

    Char

    This is a really good article. Thank you. I am off to change my affiliate links.

    David

  5. Rash

    2. October 2007 | 14:49 h

    directed to Charity: you could just make call to keywordxyz.php look like keywordxyz.php?affiliate=keyword
    and grab the keyword using $_GET and make a switch in keywordxyz.php and for each case change the url variable to match the one in the affiliate GET call.
    and after the switch just do the same header(”Location: lalal”); thingy.

  6. Charity

    2. October 2007 | 15:23 h

    @Rash - that seems really clever! Except I’m not strong on PHP, so it might be over my head :( Still, the idea of using only one file for all affiliate links is appealing, so would be worth it in the long run if I could figure it out. Time to start Googling and pouring over my PHP manual.

  7. Jimson Lee

    2. October 2007 | 16:23 h

    @Charity - if you’re not comfortable with PHP, then simply use a HTML redirect using:

  8. Jimson Lee

    2. October 2007 | 16:25 h

    I noticed the statement was omitted, for security reasons.

    Do a Google lookup on using meta http-equiv=”refresh”, that should work.

  9. Charity

    2. October 2007 | 17:31 h

    Great, thanks Jimson!

  10. simon

    3. October 2007 | 11:38 h

    i think i going to look at my affiliate links and see if i can change them

  11. Mike

    3. October 2007 | 12:27 h

    I say use the .htaccess for redirecting.
    or if your lazy use tinyurl.com :D

  12. Jimson Lee

    4. October 2007 | 08:32 h

    @Mike - I’m not a fan of using tinyurl.com because I like to see the domain of where I’m clicking :)

    Also, what happens if their DNS goes down?

    I agree with you, .htaccess is the way to go.

  13. Nicola

    16. October 2007 | 20:36 h

    I have set up a php redirect and can get it to work for normal links that are just a straight URL with an affiliate ID attached, but how do you reconfigue Amazon links to work - they have that tracking code on the end.

    For instance, a typcial amazon affiliate link for a Sony Ericsson Cellphone Search page results would be as below:

    What part of this do i put into the following redirect page codeline

    if ($linkid == “”) {$link = “AFFILIATE LINK GOES HERE”;}

    Really appreciate your help, thanks

  14. Neil Duckett

    17. October 2007 | 20:28 h

    I can get this to work no problems when it’s a straight link but for example when it’s google referall affiliate code its a block of text like ……

    google_ad_client = “pub-???????????”;
    google_ad_output = “textlink”;
    google_ad_format = “ref_text”;
    google_cpa_choice = “CAAQnfzw4AIaCJwZC9ix5DwoKN2uuIEBMAA”;
    //–>

    So how do i get this to work? My link works successfully and i can find the .php file …. it just doesn’t redirect.

    Any help is appreciated.

  15. JLB

    17. October 2007 | 22:50 h

    It looks like it should be simple. However, I don’t understand ‘affiliate link’ after keywordxyz.php in the second graphic.

    Why not just .shtml pages?

  16. Rach

    27. October 2007 | 22:42 h

    Does anyone know how to track keywords when using php redirect pages?

  17. Jenny

    23. November 2007 | 12:10 h

    Oh I’ve been looking for a way to do this. Thank you so much!

  18. Nick - road2blogging

    12. January 2008 | 06:16 h

    Thanks for this post, it has helped me a lot in understanding how to re-direct an affiliate link - much better explanation of others on page one of google, including Aaron Walls!

  19. soggyindo

    1. May 2008 | 10:42 h

    that’s a neat trick! thanks!
    one question - i’ve heard about people poaching your afiliate sales through intercepts. does that make your affiliate code any more - or any less - secure?

Join the Conversation

© 2006-2008 Essential Keystrokes | Wordpress | dKret 1.9 heavily modified by Char at Keystrokes | Hosting by HostGator