More Info »
» Home » Affiliate links guide »
Hide affiliate links using htaccess
What is htaccess?
Htaccess is server directory configuration file (apache server). With htaccess, main server configuration can be partially overridden. It is usually in root of your site, and it can be added to other directories. Can be used for redirection, password protection, to denny access for particular domains (spiders, spammers), for enabling some more functions...
It is possible that you can't see that file in directory listing.
There is solution for that without enabling that feature. Simple make htaccess.txt, edit like any normal text file, and after upload, rename htaccess.txt to .htaccess .
Important info: .htaccess is a text file, use text editor (without wrapping), upload it using FTP text mode. After uploading, check is it working. If you get server error (500), something is wrong. Edit, fix and check again.
How to hide affiliate links using htaccess
Let's say that you want to hide affiliate link or simply make shorter and better looking url.
Edit htaccess and add this line:
redirect 301 /somename http://YourAffiliateUrl
In above example, /somename could be anything, you don't need to make directory with that name, just keep in mind, if that directory already exist, every page in that dir will be redirected to YourAffiliateUrl.
Page (site) you are redirecting to, it is not on your site, so, use redirect 301, or redirect permanent, to "tell" SE spiders that it is not your page.
Your masked affiliate link (url) is looking like
For visitor, it is looking like link is leading to an
other directory of the same site.
Hide affiliate url from search engines
Use robots.txt and add code below to exclude directory "hiddendir" from crawling:
Now, edit htaccess and add this line:
redirect 301 /hiddendir/somedir http://AffiliateUrl
Instead of "somedir" you can use somepage.html, to make url more natural.
Do not fill htaccess with too many links. Server is checking htaccess every time when there is some request, that is unnecessary delay. For more links you can use script redirection and database. One simple PHP redirection script with flat text database you can download here
htaccess and mod_rewrite
Mod_rewrite can be used too, but there is no need to play with
Hiding affiliate links using mod_rewrite
To avoid filling htaccess and to hide many affiliate links mod_rewrite could be used. Many affiliate links on one page could get your site penalized on search engines. Even when search engines results pages todays are looking like parked domain page, filled with "sponsored results", they don't like affiliate links on YOUR site.
This example is if you are using only one affiliate network. Merchant link ID could be dynamically inserted and visitor redirected to affiliate link.
Now, in this example, your affiliate link number is 123 (a=123), and merchantID is 456 (m=456).
.htaccess must be placed in separate directory, say "yourdomain/redirect/" , and all "files" in that directory are redirected.
Link placed on site page is looking like "yourdomain.com/redirect/456"
To hide affiliate link from search engine spiders, add "redirect" directory in robots.txt and use "disallow"
For different affiliate networks, use different directories.
Again, don't forget, htaccess must be placed in /redirect/ (in this example) directory.
To exclude directory "redirect" from crawling (hide link from search engines),
Hide redirection links example
Also, using above example, it is possible to hide script redirection, i.e. to make redirection link looking more naturally.
Let's say that link to your redirection script is http://www.domain.com/cgi-bin/dir/go.cgi?ID=100 (could be php script, not important)
How about better looking and shorter http://www.domain.com/sites/100 ?
Again, make /sites/ directory, upload htaccess in that directory, use robots.txt and disallow (option) to be sure that search engine spiders will not follow redirections.
More details about Apache directives: htaccess mod rewrite