Affiliate marketing for beginners

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

» Home » Affiliate links guide »

Why to hide affiliate links

Purpose of link redirection and masking is to hide affiliate links from search engines, from your competitors (yes you can), and to track clicks on links.

PHP redirection examples

A few redirection examples are chosen, edited, tested, and added to this page. Along with PHP code examples, two more options are added. robots.txt could be used to block search engine spiders access to your redirection script, and .htaccess directives to make your links (url) looking more natural, and to hide scripts from scanners (bad bots). This simple (universal) htaccess mod_rewrite example can be used also for search engine friendly links (/examplepage instead of /?page=examplepage).

Important: Common error with this kind of PHP scripts, due to function used, is the warning message : "Cannot modify header information"
To avoid this in advance, be sure there is no any space or any blank line before starting tag (<?php) and after script ending tag.

Hide redirection script from search engines

To use advantage of .htaccess (friendly links), and to avoid that search engine spiders are following affiliate links, we will make folder "redirect", and add a simple directive to robots.txt:

User-agent: *
Disallow: /redirect/

robots.txt is in your root folder, if you don't see it, make it using text editor, add this code above, and upload to server. Without this in robots.txt, search engine spiders will follow your affiliate link and boost number of clicks. You will see lower conversion and blame redirection script.
Affiliate cookie is set AFTER visitor is redirected, and script doesn't have anything with affiliate cookie. If you see lower conversion, check affiliate url (is it correct?) in script.

Simple PHP redirection

header("HTTP/1.1 301 Moved Permanently");
header("Location: http://afiliateurl");

Save in /redirect/product1.php and call it as

htacces rewrite example to hide script

To hide php extension , you can use this htaccess example.

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$$1.php
RewriteRule ^([a-zA-Z0-9_-]+)/$$1.php [L]

Use url or .

Still simple PHP redirection

Difference between this, and above redirection method, is in quantity. While in above method, you need to make separate file for every affiliate link, here you need the only one file/script.

// etc... last line without comma
if (array_key_exists($_GET[id],$links))
header("HTTP/1.1 301 Moved Permanently");
header("Location:" . $links[$_GET[id]]);
else {echo "bad url";}
exit(); ?>

Save in redirect/test.php , call it as redirect/test.php?id=product1

Make link friendy and hide script using htaccess

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ test.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ test.php?id=$1 [L]

Paste code and save as htaccess.txt . Upload htaccess.txt to /redirect/ folder. Rename htaccess.txt to .htaccess.
Now, use this url to call test.php : or

PHP redirection with flat file database

For storing a few hundred, or more, affiliate links, flat text database (pipe, comma, or any kind of delimiters) could be used, for those who don't need or don't have access to MySQL base.
Example of that kind of script is now available on php link redirect script page for download. In a fact, that is "translated" Perl script.
Script and database are simple. Friendly links (url), all kinds of web robots are blocked, no false clicks in reports.

Bookmark and Share


to top