WARNING & DISCLAIMER
If you make changes to your own .htaccess file, you do so at your own risk. You should always keep a backup of any file you change and if you are unsure what you are doing, contact technical services of your hosting provider. The following tutorial is for Linux based servers.
Your server will have a folder where you upload your site. I am going to call this the “root” folder. In the root folder you may have a file called .htaccess – if it does not exist, you should be able to create it manually. Just open a text editor, and save an empty file as .htaccess
Note the naming of this. There is a period at the beginning, then the word htaccess. Some text editors may try to save this with a txt extension, but it should not have one.
The .htaccess file allows you to enter processing commands that can change the way your site behaves. e.g. you might password protect a folder, or ensure that all of the pages on your site resolve to a domain with or without the www. bit no matter what is typed into the browser. You might want to use Server Side Includes in pages with .html extension and you can set this up using the .htaccess file. I have only scratched the surface on the types of things you can do with this file, but you get the idea – it is a powerful tool to have.
You can actually find an .htaccess in any folder on your server. If a folder contains one, it is because that folder has specific requirements that the .htaccess file can offer. However, for the purpose of this tutorial, we are only concerned with the .htaccess file in your root folder.
What I want to look at here is how you can use the .htaccess file to setup and control affiliate links. The benefits of this include:
- affiliate links cloaked.
- manage all affiliate links for a site from one file (e.g. if you want to switch an affiliate link to a different merchant and you have the link on hundreds of pages, you can make just one change to the htaccess file and the link is updated on all pages ).
- URLs are more user-friendly.
Using Redirects for Affiliate Links
The idea here is that we want to create a URL to be used for a specific affiliate product.
Suppose you are selling a BluRay Disc Player from Amazon on our site. To create the redirect you need to choose a “name” for the link. Make it short, yet related to the product so you can easily find it in the future (you may end up with 100s of redirects in your htaccess file). In this case you might choose “bluray”.
To create the redirect, simply add this line to your .htaccess file (which you can edit in any text editor, though I would not use something like Word unless you know what you are doing – the file needs to be saved as plain text and Word can add extra stuff):
redirect /[LINK NAME] [AFFILIATE LINK]
Replace [LINK NAME] with the name of your link, and [AFFILIATE LINK] with the actual link you got from Amazon. You will end up with something like this:
redirect /bluray http://my-affiliate-link.com
Now, when you want to link to the Bluray player on a page of your website, you link to:
[MY DOMAIN]/[LINK NAME]
Substitute [MY DOMAIN] with your domain name and [LINK NAME] with the redirect’s link name. Here is an example:
When someone clicks this link, the web browser will go and look for a page (in fact it will look for an index page in the bluray folder) and under normal circumstances a page not found error would be returned. However, the htaccess file informs your server that whenever someone tries to access the /bluray folder, they need to be redirected to:
Look at the structure of the redirect again:
redirect /bluray http://my-affiliate-link.com
Cloaking a Clickbank Affiliate Link
Imagine the Clickbank affiliate link:
In my .htaccess file I add a line to the end of this file:
redirect /greenwidget http://hop.clickbank.net/?myid/bluewidget
When I link to this product on my site, I use the following link:
Now, imagine that this link is placed on 100 pages of your site. You get an email from the merchant saying they are closing their affiliate product (or maybe a better product comes along). Instead of manually changing the link on 100 pages of your site, you simply edit the htaccess file, and change the affiliate link that the “/greenwidget” redirect points to. Upload changes and all 100 links on your site are updated immediately.
Keeping affiliate links in one file like this allows you to make site-wide changes to links by just editing one file.
By naming your redirects with meaningful names, you can easily search for an affiliate link when you need to change it.
To end with a screenshot, here is one of my sites .htaccess file showing the redirects and a portion of code added by WordPress (since this is a WordPress site):