A Better Way To Manage Affiliate Links

One of the more lucrative monetization methods for a blog is affiliate marketing (or referral marketing). Basically, you set up your blog with an affiliate link (or referral link) and send traffic to your advertiser. For each visitor that completes an action — i.e., subscribe to a service, buy a product, etc. — you’ll get paid a fixed amount or a percentage of the sale as compensation.

Three Problems With Affiliate Links

1. Non-Descriptive

Non-descriptive affiliate links are the ones that don’t tell the user information about the site it is leading to. This is a common problem with program like Commission Junction where a typical affiliate link looks something like this:


By the way, that’s the affiliate link for Lunarpages web hosting. However, with all the phishing scams, visitors are less inclined to click on a non-descriptive link because they are not sure where they will end up.

2. Complicated

Complicated affiliate links are the excessively long ones. For example, this is an affiliate link for a Garmin Nuvi GPS through Amazon.com:


That’s a pretty long affiliate link.

3. Hard To Update

As your blog ages, it could contain hundreds or even thousands of affiliate links. This presents a challenge if one of these links needs to be updated. For example, eBay recently left Commission Junction and started its own affiliate program, forcing publishers to update all eBay affiliate links.

Using PHP Redirect To Manage Affiliate Links

The three problems above can be addressed with a simple solution if you know a bit of PHP. We will use the Lunarpages link as an example.

First, you need to create a PHP file that redirects visitors to the affiliate URL when called — let’s call it lunarpages.php. This is how the file would look like:

header( ‘Location: http://www.anrdoezrs.net/click-2899932-8291847’ ) ;

Note the Lunarpages affiliate link.

Second, upload the lunarpages.php file to your web server. I keep my PHP redirect files in a folder called go. For example:


Now, I can simply link to this nicer looking link that tells my visitors that it goes to Lunarpages instead of the ugly “anrdoezrs.net” link. Try it: http://www.blogthority.com/go/lunarpages.php

A Better Way To Manage Amazon Affiliate Links

It would be extremely time consuming to manage Amazon affiliate links using the above method — i.e., one PHP file per product. Fortunately, we can use a PHP variable to solve the problem — this way, one PHP file can handle multiple products.

First, the PHP file. Let’s call it amazon.php. This is what it would look like.

$asin = htmlspecialchars($_GET[‘asin’]);
$link = “http://www.amazon.com/gp/product/” . $asin . “?tag=your-affiliate-ID”;

Note, be sure to replace your-affiliate-ID with your ID. Again, upload the file to your web server. Now, when I need to link to an amazon product, I can do the following:


This is the equivalent of the long affiliate link in #2 above. Try it: http://www.blogthority.com/go/amazon.php?asin=B000H49LXQ

If you ever need to update any of these links, all you have to do is update the PHP file — one change and you’re all set!

Tags: , , , , , ,

24 Responses to “A Better Way To Manage Affiliate Links”

  1. Thanks! I knew it had to be simple, but I just never bothered to figure it out.

    Another side benefit is that you can better track who and how often these are clicked by checking your own server logs for the hits to these php pages.

  2. AP says:

    Does this also help with SEO? i.e. you are outbound linking to your own website rather than linking to some redirect.

  3. Great tips. Your PHP file codes are definitely a nice way to make a link a professional. I am a big fan of eBay affiliate program. I have bunch eBay affiliate websites. Their recent changes of leaving Commission Junction really made me sick. It took me lot of time to convert my all site. I have a feeling that thier all new eBay links are not tracking commissions properly.

  4. Pinyo says:

    @AP — I am not an SEO expert, but I assumes it helps by reducing the number of unnecessary outbound links.

    @Auctionfreedom — I am sorry to hear about your predicament. I just joined the new eBay program, but I make minimal amount so I can’t really compare. I supposed any program could cheat us out of our money if they wanted to.

  5. Mrs. Micah says:

    Pinyo, that’s amazing. 🙂 This is getting del.icio.usd onto my to-do list. Especially the Amazon one…so much easier to manage.

  6. Patrick says:

    Very slick. I wish I would have known a bout this when I started out, but no worries. I’m thankful a friend showed it to me recently and I do it for most links now.

  7. Frugal Dad says:

    Thanks for solving the mystery (for me) behind how to do this. I see implemented at most of the “big” blogs now, but never knew how to implement it. Great stuff!

  8. DR says:

    Pinyo, great article! I’ve used php redirects before, but not quite the way you suggest. I implemented your suggestions in a couple of minutes and it worked like a charm. Thanks!

  9. I do the first redirect, but I don’t do the Amazon one. I feel that Amazon is a pretty trusted source and people are generally not upset by clicking on it. If they can read the link text, say Garmin Nuvi and scroll over it, it should be all they need.

  10. Pinyo says:

    @Mrs. Micah — You’re welcome. I learned this trick from the best in the business. 😉

    @Patrick — Yeah, any new trick is a pain to implement if you’ve been at it for a while.

    @Frugal Dad — Took me a while to learn it too.

    @DR — You’re welcome. Glad to hear it works well for you.

    @Lazy Man — You have a point about trust, but I like the ease of setting up new referral link without knowing the structure of the long URL and without having to go into Amazon Affiliate interface.

  11. Rufas says:

    The amazon.php script doesn’t work. It gives me this error:

    Parse error: syntax error, unexpected ‘:’ in amazon.php on line 3

    Any help?

  12. Pinyo says:

    @Rufas — I think it may be quote problem since WP automatically replaces normal quotes to smart quotes. Try this.

    < ?php $asin = htmlspecialchars($_GET['asin']); $link = "http://www.amazon.com/gp/product/" . $asin . "?tag=your-affiliate-ID"; header("Location:".$link); ?>

  13. Rufas says:

    Thanks Pinyo, It works wonderfully now 😉

  14. Bill says:

    Great tip on Amazon. I hate going to their Affiliate site.

  15. […] Want to set it up so you can have friendlier urls for your affiliate links? Check out this tutorial on blogthority. […]

  16. Interesting approach. Thanks for sharing. Thought I’m not huge into affiliate marketing, this is a great way to do it.

  17. Thanks Pinyo. Amazon tip was working for me great

  18. […] you have your own website. For additional information on this technique, check out this great PHP redirect […]

  19. Stefan says:

    Isn’t the Amazon tip against the new regulations they’ve put in place where they state that only plain links and image links may be used to link to Amazon products?

  20. Pinyo says:

    Stefan, I have not look at Amazon policy lately — it’s been a while since I wrote the article. I’ll check out their TOS.

  21. NG says:

    Any update on whether this violates Amazon’s rules?

  22. Pinyo says:

    @NG – Sorry, but I have not look into it yet.

  23. Mike Goldy says:

    Pinyo, first thank you. My question is the following. I use CJ and below is my PHPscipt:

    How can I just have the script pull the URL from the referring page (page I have the link on) instead of having to make my links with an sid. EX: /merchants/bestbuy.php?kw= pmbinc
    Your help would be gratefully appreciated and remunerated if you would like.

  24. Mike Goldy says:

    Pinyo, first thank you. My question is the following. I use CJ and below is my PHPscipt:

    How can I just have the script pull the URL from the referring page (page I have the link on) instead of having to make my links with an sid. EX: /merchants/bestbuy.php?kw= pmbinc
    Your help would be gratefully appreciated and remunerated if you would like.