How to Make a Redirect for Affiliate Links
By
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.

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:

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.












24 Comments
October 2nd, 2007 at 10:34 am
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
October 2nd, 2007 at 1:43 pm
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.
October 2nd, 2007 at 1:51 pm
Jimson – my Amazon links are the ones I do not tend to redirect.
Charity – yes, I create a separate file for each affiliate.
October 2nd, 2007 at 2:33 pm
Char
This is a really good article. Thank you. I am off to change my affiliate links.
David
October 2nd, 2007 at 2:49 pm
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.
October 2nd, 2007 at 3:23 pm
@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.
October 2nd, 2007 at 4:23 pm
@Charity – if you’re not comfortable with PHP, then simply use a HTML redirect using:
October 2nd, 2007 at 4:25 pm
I noticed the statement was omitted, for security reasons.
Do a Google lookup on using meta http-equiv=”refresh”, that should work.
October 2nd, 2007 at 5:31 pm
Great, thanks Jimson!
October 3rd, 2007 at 11:38 am
i think i going to look at my affiliate links and see if i can change them
October 3rd, 2007 at 12:27 pm
I say use the .htaccess for redirecting.
or if your lazy use tinyurl.com
October 4th, 2007 at 8:32 am
@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.
October 16th, 2007 at 8:36 pm
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
October 17th, 2007 at 8:28 pm
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.
October 17th, 2007 at 10:50 pm
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?
October 27th, 2007 at 10:42 pm
Does anyone know how to track keywords when using php redirect pages?
November 23rd, 2007 at 12:10 pm
Oh I’ve been looking for a way to do this. Thank you so much!
January 12th, 2008 at 6:16 am
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!
May 1st, 2008 at 10:42 am
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?
August 27th, 2008 at 12:39 am
Here’s a question. What is you are just learning, have a website wanting to add affiliate links but can fit your computer knowledge in a 1/4 of a thimble? Any take me by the hand instructions out there?
October 23rd, 2008 at 12:48 am
That is a great way to add affiliate links. I have been using that for a couple of years now, because it is easy to manage links.
February 20th, 2009 at 1:44 am
The good news is that you can use a wordpress plugin to redirect links for you. Im pretty sure its called golinks. Hope this helps
April 29th, 2010 at 3:17 pm
Hi, a simple online solution to this problem that doesn’t require any programming can be found at http://linkshiftr.com/.
Linkshiftr is a collection of tools for marketers that combine link redirection, link rotation, statistics, link shortening, conversion tracking, and other features to streamline the organization and efficiency of online marketing campaigns (all features are free except conversion tracking).
Keywords can be added to the end of links allowing you to collect any information you want from your links as well!
If you like the service or have questions, let me know at max@linkshiftr.com
May 25th, 2010 at 5:56 pm
Fantastic Tutorial. I’ve been hunting the web for info to do this. This will really come in handy for clickbank!