Hiding Affiliate Links using htaccess
By Reaper-X on Sep 8, 2007 in Apache, Guide, Webmaster Tools
Today i’m going to tell you on how to hide your affiliate links or any other links you want to hide (see the right sidebar of this site) using a simple htaccess redirect trick, just in case you didn’t know about it, and of course i’ve only tested this on Apache HTTP Server only (Windows and Linux version) so if you’re using any other webserver to serve your webpages … i’m quite sure that this trick is not going to work, and you’ll have to use some redirect script to do it
But as a side note, this redirect trick (or any other redirect trick using php, etc) may or may not working especially if your site mostly visited by tech savvy users even if the affiliate website itself didn’t show your referal link, because they can always see it through the HTTP header
Redirecting from the root of your domain name
Step to do it :
Open or create new .htaccess file on the root of your www / public_html directory and add this line :
Redirect /myaffiliate http://www.myaffiliatewebsite.com
the above line mean, if you type http://www.yourdomainname.com/myaffiliate it’ll be redirected automatically to www.myaffiliatewebsite.com using 302 Found HTTP Header
But what if you want a 301 Moved Permanently HTTP Header instead of 302 HTTP Header (almost every redirect trick i’ve seen so far is using 302) ? … if that’s what you want … then you can use this
Redirect 301 /myaffiliate http://www.myaffiliatewebsite.com
Redirecting from subdirectory
Step to do it
- Create new directory (for example : redir)
- Create new .htaccess inside and add these into your newly created htaccess file
Redirect /redir/affiliate http://www.affiliatewebsite.com
The above line mean, if you type http://www.yourdomainname.com/redir/affiliate it’ll be redirected automatically to your affiliate link
Redirect to multiple product in the same affiliate website with a single line (useful on site like Amazon)
Let’s say you’ve become an Amazon Affiliate, and you want to link to that product page without adding new line into your htaccess file … then you can add this line into your .htaccess file
RewriteRule ^show/(.*)$ http://www.amazon.com/exec/obidos/ASIN/$1/YourAmazonID [L]
What the above line do is, whenever you type http://www.yourdomainname.com/show/ANY-AMAZON-PRODUCTID it’ll be redirected automatically to http://www.amazon.com/exec/obidos/ASIN/ANY-AMAZON-PRODUCTID/YOUR-AFFILIATE-ID
Another example on how to make your Amazon Link look pretty is you can also use this :
RewriteCond %{QUERY_STRING} id=([^&]*)$
RewriteRule ^products\.asp$ http://www.amazon.com/exec/obidos/ASIN/%1/YOURAMAZONID? [L]
Basically what the above code do is, everytime you type mydomain.com/products.asp?id=AMAZON-PRODUCT-ID even without the existence of products.asp file on your webserver, it’ll be redirected automatically to the Amazon link using your Referal ID :)
As a note, Mod Rewrite must be enabled on your server to do the last redirection trick
That’s it … i hope this small tips can be useful for you :)

Website RSS Feed
Stumble this post
Bookmark this post on Del.icio.us
Submit this post to Digg
Submit this post to Reddit
Print this
Trackback URL












Great tip on the Amazon referral link, I hadnt even thought about that when I was searching for the first tip.
Excellent tip. I'm going to use this technique to see how it works for me. Thanks again.
Your welcome, hope it'll be useful for you :)
Hi,
I'm having a bit of trouble with this. On my site the out link displays as a friendly URL:
http://www.mydomain.com/out.php?title=Amazon-com_The_Orange_Box_Video_Games_Windows
I tried using this code in the htaccess file:
RewriteRule ^out/(.*)$ http://www.amazon.com/exec/obidos/ASIN/1/myamazonIDbut it didn't work. I also tried placing a regular Amazon.com link to see if the redirect worked but it didn't. Is the above code wrong?
Thanks. Great site.
Sorry, the code was this:
RewriteRule ^out/(.*)$ http://www.amazon.com/exec/obidos/ASIN/1/myamazonID
# Layton
I'm really sorry for late reply because i didn't see your comment
about your question, could you try using the amazon code using the RewriteCond code? because it seems that you want to redirect query string
I’m going to use this technique also
good technique
Thanks for your project. I like this site. KEEP IT UP..n
I enjoy your site very much! THANK YOUO