How to Redirect a Link to Your Amazon Associates ID

by Michael on September 3, 2012 · 1 comment

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:

<?php
$asin = htmlentities($_GET['asin']);
$link = "http://www.amazon.com/exec/obidos/ASIN/".$asin."/ref=nosim/jammersix-20";
header("Location:".$link);
?>

(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:

http://www.jammersix.com/external/amazon.php?asin=xxxxxxxxxx

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:

http://www.amazon.com/exec/obidos/ASIN/xxxxxxxxxx/ref=nosim/jammersix-20

For example, this link:

http://www.jammersix.com/external/amazon.php?asin=1430232498

results in an Amazon link that points to a handy book about PHP solutions for dynamic web design. The end product looks like this:

http://www.amazon.com/exec/obidos/ASIN/1430232498/ref=nosim/jammersix-20

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 /dp/.

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.


{ 1 comment… read it below or add one }

Erica September 6, 2012 at 2:01 pm

Thanks for the tips. I use a redirection plugin which allows me to create a link using my own url. This way if they change the structure I just go in the back office and change the link that it directs to.

Reply

Leave a Comment

Previous post:

Next post: