How To Cloak Affiliate Links Using Htaccess
You’ve undoubtedly seen the super long affiliate links. For a variety of reason these can be less than ideal. For one, long url’s can break in an email and in a best case scenario, people may just not click because they recognize it as an affiliate link. Here’s how to cloak your affiliate links using .htaccess
So, besides the broken links in emails and people not clicking because they look affiliate links, why else would I consider cloaking affiliate links?
The best reason of all is that you maintain full control over those links and where they redirect to. With a url shortener service like tinyurl, you are at their mercy. Should they decide to close the doors one day or sell out to some business who wants to charge a fee, or even worse, redirecting a portion of your links without your knowledge.
You also have the ability to quickly change where your links redirect to at any time, this applies to line by line redirects and not a broad, entire merchant redirect. I’ll explain more about those.
Let me start by saying that you must be on an apache server, .htaccess does not work on Windows servers.
I’ll cover a couple different ways that I like to cloak affiliate links.
1. Redirection for an entire merchant using variables.
Rather than have a hundred links like
send link A to Site A
send link B to Site B
We can tell the server to send everything that comes into folder ”recommends” to Site A which in this case is Clickbank.
RewriteRule ^(.*) http://AFFILIATE.$1.hop.clickbank.net [L]
You can download this code in a text file here, replace AFFILIATEwith your clickbank id. Create a folder named “recommends”, change the name of your htaccess to .htaccess and make sure there is not .txt extension, upload it into the newly created “recommends” folder.
You are now ready to start setting up your cloaked affiliate links. From now on, instead of linking directly to the merchant, you will link to the “recommends” folder on your own site and just add the publisher to the end of your link, the htaccess with take the publisher, insert it into the $1 position and off they go.
If you’re not quite sure what the PUBLISHER is, just go the the Clickbank Marketplace, choose which product you wish to promote and click the “create hoplink” link. You will be given a link that looks like this.
The bolded blue text is the publisher, so your actual link would look like this…
NOTE: the “recommends” folder is just an example. I use the folder “go” among others., you could name the folder anything you like, “more”, “details”, “coupon”, “discount”. Just change the “recommends” in the .htaccess to match and change your links accordingly.
Counting Your Cloaked Link Clicks
The downside of cloaking your links with htaccess is you won’t know how many times your links are getting clicked on. Well, it took me a bit but I found a way to not only count those clicks but also to log ip’s. If you know of a better method, please leave a comment below, I’d love to hear about it.
Here’s how to do it
Download Click Counter Deluxe (it’s a free click counter) and install it. If you need a little help with unzipping, uploading files, etc.., you can probably find some free video demonstrations at Webmastering 101 Video Guide. Just spend a few minutes watching some of the relevant videos if you need to.
Now that you’ve installed the click counter, we need to modify our .htaccess file to send our clicks through the script before redirecting. If you installed the click counter in the default directory, your new .htaccess will look like this…
RewriteRule ^(.*) /ccd/index.php?xrl=http://AFFILIATE.$1.hop.clickbank.net [L]
Download this code in a text file here.
You can now log in to your click counter admin area and monitor your clicks.
Now, Let’s Do Amazon Links
For this, we’ll assume you are going to create a folder named “amz”, you can change it to whatever you like however, just change the folder name in the .htaccess file and create your links accordingly. Once you’ve created your “amz” folder, download the text .htaccess file for amazon hereand edit it by adding your clickbank affiliate id, rename it to .htaccess and upload into your “amz” folder (or whatever folder you created for this). Make sure the amazon url is all on one line, it may wrap here due to width constraints.
RewriteRule ^(.*) http://www.amazon.com/gp/product/$1?ie=UTF8&tag=AFFILIATE-ID&linkCode=as2&camp=1789&creative=9325&creativeASIN=$1 [L]
In the code above, you will see two $1, these will be replaced by the ASIN when you link to the folder like so…
No more going through the Amazon affiliate area to create product links, just go directly through Amazon, when you find a product you wish to promote, click through to the detail page and find the ASIN and then create your link.
You will find the products ASIN under the Product Details section on the product page.
Product Dimensions: 3.7 x 1.6 x 2.5 inches ; 6.2 ounces
Shipping Weight: 3 pounds (View shipping rates and policies)
Shipping: Currently, item can be shipped only within the U.S.
Item model number: A590IS
Using the above as an example which is for a Digital Camera, our link would look like
If you want these counted, just add
into your amazon .htaccess file as it is in the clickbank .htaccess file. It will send the clicks through your counter script before redirecting.
That’s It For Today
I think that’s a good start for today. I will pick up where we left off here in a future post and we’ll do one .htaccess file for a multitude of individual links, not a broad, merchant based redirect like we did here.
Also, there are many, many other things we can use .htaccess and mod rewrite for that will help in your online business and we’ll get into more of those as well so be sure and come back.
Thanks, Gail, great post! I got a little confused around the ‘how to count the cloaked links’ section but I think that was more due to the time (3am) than anything else. I have tried your methods again this morning though and they work perfectly.
I’m using it on an unindexed landing page, driving traffic via PPC, and promoting a clickbank product. So far so good…
Glad you were able to get it going! Your problem with understanding probably had less to do with it being 3am when you were reading and more to do with it being 3am when I wrote it.
I tried your cloak link for clickbank, and it worked perfectly on the first time. the same cloak link can be used for commission junction as well?. I looked at your cloak link generator, not sure I understood it well, to give it a try.
thanks for your help Gail.
Glad you were able to use the clickbank code easily. I don’t use CJ much and haven’t tried to see if I could cloak the links. For the misc items I do promote, I use my own url shrinker. You can see it at http://wahguide.com/url , you are free to use that one if you like or you can install the script and use on your own site. You can download it at http://wahguide.com/freebies/url-shortner.zip , I also put a link to it in the freebies section. It’s easy to install and the readme file is included. If you have any problems with it, just let me know. On a side note, I think it would not be difficult to do Ebay links and I’ll look at that sometime soon.
Thank you so much for the reply. the url shrinker seems attractive. No Gail I did not use it yet, though just tested it. Just saw your reply, thought I will say thanks. will catch up with you once I try it out. Thanks again Gail.
hi nice post pretty useful I got this to work, although it would be nice to know how to also include .html extension on the end instead of just http://yoursite.com/amz/B0011ZCDKS. I’m sure this can be all done in .htaccess file just not sure I’m a little bit of a green horn lol!
It’s no problem to add the .html to the end.
Then your link would look like
This works with clickbank as well. And you can change the html to any file extension you want. It is basically just ignored anyway.
thanks for useful tips you let me to know more about .htaccess.
how i can indexing my newly created sites using .htaccess in search engines like google?
thanks alot for article.
Whoa… this site is pretty awesome your layout is really well designed, and your blogs are (judging from what i’ve read) very interesting. heehee… consider yourself favorited.
Hello, I enjoy reading through your blog, I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the better of luck for all your blogging efforts.
Excellent post! I’ve switched over one of my dynamic websites to a static .html website and was looking for a more efficient way to cloak my Amazon links since I couldn’t use the features of plugins.
Thanks for sharing!