If you have an Amazon Associates account, you might be wondering about the best way of managing your links. Sure, you could create a different link for every product, but that quickly gets unwieldy. Surely there’s a better way. Right?
Wouldn’t it be nice to feed the product ID into a standard link and let your web server craft the link for you?
What I’m talking about here, of course, is creating a redirect for your Amazon (or other) affiliate links. If you’re using WordPress to run your site, you could use a plugin to manage your affiliate redirects. But, as I’ve noted before, I don’t like using plugins for things that can be easily achieved with a bit of custom code.
What happens if the plugin’s creator loses interest and stops updating? It happens. And if it happens to you, you’ll be stuck with a huge cleanup project on your hands. Not worth it when you can roll your own solution in less time than it takes to find and install a plugin. Plus, the method outlined here works for just about any backend, not just WordPress.
The simplest solution (in my book) is to create a PHP redirect. To do this, create a
.php file (i.e., just a text file containing a bit of PHP code) with the following:
$asin = htmlentities($_GET['asin']);
$link = "http://www.amazon.com/exec/obidos/ASIN/".$asin."/ref=nosim/jammersix-20";
(sorry about the awkward line wraps)
Be sure to replace “jammersix-20” with your own affiliate ID — or don’t, if you’re feeling generous.
I named this file
amazon.php and stashed it in
/external at the root level of the domain. Thus, to use it, I simply link to:
If you replace xxxxxxxxxx with the actual Amazon product ID number (ASIN = Amazon Standard Identification Number) the redirect will produce a well-formed Amazon link with your Associates ID that points to the product of interest.
The end product will look like this:
For example, this link:
results in an Amazon link that points to a handy book about PHP solutions for dynamic web design. The end product looks like this:
Go ahead, click both versions. They work exactly as advertised.
Wondering how I found the ASIN? The easiest way is to just look at the page url after you’ve navigated to the product of interest. You’ll see it embedded in the Amazon url right after
The beauty of this approach is that: (1) you’re not dependent on a third-party developer, and (2) if you ever change your affiliate ID in the future (or if Amazon changes the acceptable link structure) you only have to update it in one place.