February 8th, 2008 | by RichSage
Managing URLs Using HTACCESS File
Category: WEB TOOLS
Using a HTACCESS File to Manage Affiliate URLS
Indeed, htaccess files are great for managing URLs of all kinds. From Affiliate Program links to URLs that you post in signature files to e-books –htaccess helps you manage them all.
I am sure that you’re aware of losing affiliate sales commissions when the actual “affiliate URL” is published for the world to see? For example, you could have a URL pointing to http://www.some_affiliate_site.com/track/affiliate_program.php?my_id_is_12345

Often that type of URL will jeopardize your sales commissions for several reasons:
- The URL can be too long for e-mail.
- Perhaps a potential buyer might not “copy and paste” accordingly.
- There are a myriad of other reasons as well for you to lose the sale.
- Then there is the problem of publishing an affiliate URL in an e-book or review
What is the best way to control the traffic that comes from your advertising and leads to your affiliate sales? Or just for the sake of it, having a short URL. None of these tasks can be achieved if you are using a URL that is given out by the many Affiliate Programs.
The best solution that I’ve found is a rather simple and an elegant one –by using a simple HTACCESS file, which is a text file (.txt) that has a period ( ” . “) before the “H”:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^test.php$ http://www.GO_TO_URL.com [R=301]
RewriteRule ^clickbank.php$ http://uapnet.reseller.hop.clickbank.net [R=301]
</IfModule>
Steps to Setup a htaccess file:
- Copy the above code and save as my_htaccess_file_name.txt
- Note that in my example above, lines 3 and 4 are the same. They just “point” to different locations and of course, direct the visitor to different affiliate examples.
- Each time you add a new affiliate program, product or just have a location to point to, all you need to do is edit the above file. After “^” is the name you’ll give each url. For example, all of my urls point to “/go/” –So, all I do is put http://www.richsage.com/go/clickbank.php and “poof” just like that the affiliate URL is delivered to the browser.
- There is a “space” after the “$” sign.
- After that is the URL, following that a closing statement with “[R]“.
- Then upload the file to the server –in the folder that you’ll place the file and immediately change the name to “.htaccess” and you’re done!
- Then test a few URLs to make sure. In fact, each time I add a new URL I test it to make sure. That’s it. You’re ready to rock ‘n roll!!!
The above file is rather unique because you cannot see it residing in the hosting folder using an FTP program. At least I cannot, while using FileZilla, my choice of FTP programs. For example, I’ll connect using FileZilla to my hosting server, which does not display the file for security reasons. However, if I enter the hosting account from the admin panel, it’s there!
The way I get around this issue is to always save the .htaccess file as a .TXT file on my workstation. So, I’ll just save a text file as My_htaccess_file.txt –only after uploading the file to the server do I change the name to .htaccess –which you can do by using your FTP program. Of course, right after doing that, it will disappear, but trust me, it’s there and doing it’s job!
NOW a BIT of TESTING:
It’s nice to have done all of the above, but only a fool will not check it. Now go to the e-book or your web site and click the link that is managed by the .htaccess file. It works! Then you’re in business!
Carpe Diem,
Rich Sage
- Popularity: 4% [?]
- Perfect FTP Client FileZilla 3.0 and It’s FREE
- Small Stuff
- Rich Sage Moving Checklist
- E-Book Publishing and Planning
- Affiliate Program
Press to 



There are two very dangerous elements to the above advice.
1. FTP programs often hide all filenames that begin with a dot, and you could inadvertantly over-write a pre-existing .htaccess file, and that would wipe out all the settings your host had already stored in the file. Investigate the options within your FTP client to “show filenames that begion with a dot”. Almost every FTP client does have that facility (including FileZilla).
2. You have used [R] in the redirect code. That generates a 302 redirect and that is a big problem. As a “temporary redirect” you expose your site to a myriad of duplicate content issues, and on occasions the “302 redirect URL hijack” problem. Change the code from [R] to [R=301] to avoid that problem. Use the Live HTTP headers extension for Mozilla Seamonkey or Mozilla Firefox to check that you really do get the correct HTTP response codes.
Thanks for the follow up…
For #1, note that I advice to put the htaccess file in its own folder. In my case, that is the ONLY file in that folder.
As for #2, again, you are correct –a permanent redirect is far superior to a temporary one. I am making those changes asap so that my readers have better advice.
Thanks,
Rich Sage
“The above file is rather unique because you cannot see it residing in the hosting folder using an FTP program” - of course you can! Just go to View -> Show hidden files in FileZila
HI Kasia,
Thanks for that insight. I tried it, but still the htaccess file does not show for security reasons. I’ll look into this further and update on a FileZilla review. Thanks for the note.
Rich Sage.
FOLLOW UP… HTACCESS FILE Viewing… FileZilla the free software program has had several updates since I wrote this article.
I have NOT had a problem seeing this file via FileZilla since the updates.
Rich Sage