How to mask an affiliate link using a server side scripting
language.
There are three parts to putting masking redirects in place:
The redirect page – call it whatever
you want. For this example we will call it ‘redirect.php
The robots.txt file - used to restrict areas
of your websites that are considered private or have some kind
of security sensitivities, or, are out of date.
Affiliate links – these will link to
redirect.php
Create The Redirect Page
Create a subdirectory called ‘redirects’, ‘products’,
‘link’ or ‘recommends’ – you can call
it whatever you like.
Create a file in that subdirectory to contain your outward scripts.
You can either use a single file or you can split them to help organize
your product groups. For the purpose of this example, I will use:
‘redirect.php’
Redirect Page Script
Create a new file in your HTML editor - save it as 'redirect.php'.
If you are using Dreamweaver - open the source view and strip out
the HTML code that DMX adds automatically - you only need a clean
page.
$linkid – refers to the links we will use
from the pages with affiliate links on. Each link is assigned a
number and placed into a conditional statement. The statement compares
the $linkid value and assigns the $link variable the correct url.
The next two lines forward the browser to the $link location url
using the header function in php.
Add as many links as you need, most probably every time you add
a new link to your site that needs masking.
Upload the file to the new directory on a php supporting web server.
The Robots.txt File
You now want to block that subdirectory in the robots.txt file,
using the following script:
Disallow: /recommends/
Or you can just block the file [if you have other files in that
subdirectory you want indexed], using the following script
Disallow: /redirect.php
This will prevent any search engine spider from following links
on your webpages to that directory, and knowing what is the final
destination URL of the link on your web page.
If you want to be doubly sure, put both:
Disallow: /recommends/
Disallow: redirect.php
NOTE: This assumes that your robots.txt file uses
User-agent: * [which covers all the bots], otherwise you will need
to add specific lines for each bot, for example:
The ‘disallow’ line tells the robot that it cannot crawl
that file. In this case , we have put redirect.php file in the root
of the server, but you can add it anywhere. Save and upload your
completed robots.txt file to the root of your server.
The Affiliate Links
Now, instead of using the affiliate URL link on your page, use
links in the format:
http://www.yourdomain.com/recommends/redirect.php?id=[x] where 'x'
identifies the affiliate link.
You now need to enter the redirect ID into the product.html file,
for instance
Your product.php script should then do the mapping from 'id' to
affiliate URL and then perform a 301 redirect to this URL.
Video Demonstration
For a video demonstration on how you can do this [14mins]