Main Website RSS FeedCurrent Article

Hiding Affiliate Links using htaccess

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

  1. Create new directory (for example : redir)
  2. 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 :)

RSS Feed for This Post10 Comment(s)

  1. 1
    Ravi | Nov 29, 2007 at 23:57 / 11:57 PM | Links to this comments | Reply

    Great tip on the Amazon referral link, I hadnt even thought about that when I was searching for the first tip.

  2. 2
    Edwin | Jan 24, 2008 at 6:14 / 6:14 AM | Links to this comments | Reply

    Excellent tip. I'm going to use this technique to see how it works for me. Thanks again.

  3. 3
    Reaper-X | Jan 24, 2008 at 17:32 / 5:32 PM | Links to this comments | Reply

    Your welcome, hope it'll be useful for you :)

  4. 4
    Layton | Feb 13, 2008 at 11:56 / 11:56 AM | Links to this comments | Reply

    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/myamazonID

    but 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.

  5. 5
    Layton | Feb 13, 2008 at 11:59 / 11:59 AM | Links to this comments | Reply

    Sorry, the code was this:

    RewriteRule ^out/(.*)$ http://www.amazon.com/exec/obidos/ASIN/1/myamazonID

  6. 6
    Reaper-X | Feb 23, 2008 at 6:24 / 6:24 AM | Links to this comments | Reply

    # 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

  7. 7
    hgh | Mar 25, 2008 at 20:45 / 8:45 PM | Links to this comments | Reply

    I’m going to use this technique also

  8. 8
    frank | Aug 2, 2008 at 23:37 / 11:37 PM | Links to this comments | Reply

    good technique

  9. 9
    jammarlibre | Aug 19, 2008 at 18:35 / 6:35 PM | Links to this comments | Reply

    Thanks for your project. I like this site. KEEP IT UP..n

  10. 10
    Ron | Aug 23, 2008 at 12:59 / 12:59 PM | Links to this comments | Reply

    I enjoy your site very much! THANK YOUO

RSS Feed for This PostPost a Comment

Line and paragraph breaks automatic, e-mail address never displayed, avoid using spammy words or phrases to prevent your comment from going into the oblivion, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>