Essential Keystrokes is…

where I share my favorite tips, tools, reviews and commentary on web design, marketing, blogging, new media and related topics. For more about this site and the voice behind it, check out my About page.


SubscribeFollow me on TwitterLinked In Stumble Upon What I Digg Email me

How to Make a Redirect for Affiliate Links

By Char

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.


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.


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:

Categories : Tutorials



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 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. :)


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

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



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



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.


@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.


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


I noticed the statement was omitted, for security reasons.

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


Great, thanks Jimson!


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


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


@Mike – I’m not a fan of using 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.


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


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.


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?


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


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


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!


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?


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?


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.


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


Hi, a simple online solution to this problem that doesn’t require any programming can be found at

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


Fantastic Tutorial. I’ve been hunting the web for info to do this. This will really come in handy for clickbank!


Thanks so much Char! This was so easy and worked INSTANTLY! Other tutorials online are so damn confusing and unnecessarily long.

I’ll definitely be coming back to your blog for more tutorials! Keep up the great work you’re doing.


Leave a Comment


Team Training NE Celiac Family