I offered a simple solution to redirecting affiliate links using .htaccess previously now heres one using good old faithful PHP.
Save the following code as a .php file, naming it is your choice. (For the example it is called link.php).
$path = array(
'link-1' => 'http://www.aterriblelongaffiliatelinkhere.co.uk',
'link-2'=> 'http://www.anotherterriblelongaffiliatelinkhere.co.uk';
if (array_key_exists($_GET['id'], $path)) header('Location: ' . $path[$_GET['id']]);
?>
replace the ‘link-1′ etc with a keyword describing where the link is going and also the corresponding URL of the affiliate link, when you add more than 2 links make sure the last link doesn’t have the comma after it.
Upload to the root of your website
Now if you go to www.yoursite.co.uk/link.php?id=link-1 it will redirect to ‘http://www.aterriblelongaffiliatelinkhere.co.uk
If you want to clear that up even more
Put the following lines in your .htaccess file
RewriteEngine On
RewriteRule ^go/([/_0-9a-zA-Z-]+)$ link.php?id=$1
Now if you go to www.yoursite.co.uk/go/link-1 it will have the same effect as above.
This works fine for any website using affiliate links, that includes Wordpress. I use this method to keep the number of plugins I install down to a minimum.
Hope it is of some use.
0 comments ↓
There are no comments yet...Kick things off by filling out the form below.
You must log in to post a comment.