Automatically adding Amazon affiliate codes
January 11, 2012 2:27 PM   Subscribe

Is there a straightforward way to transform Amazon links to add an affiliate code?

I understand that Metafilter rewrites Amazon links to add Matt's affiliate codes, and I'd like to do the same for a site I run. Is there a straightforward way of doing it? It would be good to accept and identify any of Amazon's multiple formats.

I can either do this server-side with java, or in the page with javascript.

(Bonus for catching and stripping out existing affiliate IDs).
posted by fightorflight to computers & internet (4 answers total) 6 users marked this as a favorite
JavaScript
JavaScript
PHP/JS (for PHP->Java inspiration)
posted by Foci for Analysis at 2:44 PM on January 11


Find the ASIN in the URL, grab that, and rebuild the link from scratch.
posted by kindall at 2:46 PM on January 11


This question I asked a couple of years ago should help. On the odd chance that you're using Wordpress, the very last comment is a link to a plugin that does it automatically.
posted by jbickers at 7:30 AM on January 12 [1 favorite]


Oddly, I just did this last week for Mefightclub. I created an extension in PHP to the forum software I'm using, with a regex I found somewhere to break up the URL on display then tack on the affiliate ID. The URL is stored unaltered in the db, just rewritten at display time, in case I ever need to change affiliate codes or something.
posted by stavrosthewonderchicken at 5:50 PM on January 15


« Older I've volunteered to set up and...   |  What equipment setup do I need... Newer »

You are not logged in, either login or create an account to post comments