Affiliate marketing for beginners

freewebs image
More Info »
| RSS Feed | sitemap | Contact 

» 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.
Real name of htaccess file is ".htaccess", and it is hidden (actually, it is file extension), so you can't see that file if "view hidden files" in your FTP is disabled. Enable that feature in your FTP software, or add "-al" option to see hidden files.

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.
In web site log, these requests are appearing like request for directory (or file), and it is possible to count clicks on affiliate link, just counting those requests. Can be used to count clicks on other links too, like on this site.

Hide affiliate url from search engines

Use robots.txt and add code below to exclude directory "hiddendir" from crawling:

User-agent: *
Disallow: /hiddendir/

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
htaccess too much. Mod_rewrite is usually used to "transform" PHP script requests to "search engine friendly" links. With PHP redirection, affiliate links are already hidden, and using Mod_rewrite, if it is not necessary, can overload server. Why? Search engine spiders. Following many links with fast requests, server can be overloaded, and your hosting company doesn't like that. That was known as "Google bombing". Now, there is yahoo bombing too.

So, if you see something like "maximum number of instances xxxxxxx reached" in error log, be sure that google or yahoo spiders are visiting your site. "Ugly" redirection you can hide using JavaScript MouseOver code.

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.

RewriteEngine on
RewriteRule ^(.*)$$1 [L,R=301]

Link placed on site page is looking like ""

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),
add this to robots.txt:

User-agent: *
Disallow: /redirect/

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 (could be php script, not important)

How about better looking and shorter ?

RewriteEngine on
RewriteRule ^(.*)$$1 [L,R=301]

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

Bookmark and Share


hide links htaccess

to top