Shortening (Affiliate) Links For Prettier Linking
I recently received an e-mail from an internet marketer I purchased an eBook from that was touting a $7 eBook about cloaking affiliate URLs, so instead of buying the useless guide I decided to make this post.
Now let me first say I don’t have a problem with using these techniques to shorten URLs as sending an affiliate link via an e-mail can potentially cause the URL to be split up and not work properly. (Keep in mind that you should never use these types of URLs in hopes to trick people into following your spam.)
Charging someone $7 for this type of guide is robbery, mostly because this type of information is freely available on the internet.
You could probably piece this together on your own by searching Google, but I hope this post makes for a quick reference guide to shortening links using a few different methods.
One way to shorten a link is to use plain ol’ HTML:
<html><head><meta http-equiv="refresh" content="0; URL=http://www.theurl.com"></head></html>
Another way of shortening a link is to use JavaScript:
<html><body>
<script language="javascript">
<!--
window.location.href="http://www.theurl.com";
//-->
</script>
</body></html>
You can use these techniques to redirect the typical user, but to redirect everyone you might consider a server side technique using PHP or Perl.
To redirect someone with PHP use the following code:
<?php location("http://www.theurl.com"); ?>
To redirect someone with Perl use the following code:
#!/path/to/perl
print "Location: http://www.theurl.com\n\n";
Would you pay $7 for that type of information? Maybe, but in this world of everyone wants to make a buck I’ll give these to you for free.
To see these different methods in action use the following redirects to CNN.com:
HTML: cnn.html
JavaScript: cnn_js.html
PHP: cnn.php
Perl: cnn.pl
If you enjoyed this post, get free updates by email or RSS.

























Checkout These Related Posts
10 Comments so far »
Reed said
on April 5 2007 @ 11:56 am
These are good tips, thanks.
Is there any way to stop robots from crawling my redirect script that I wrote using PHP?
Ryan J. Parker said
on April 5 2007 @ 1:04 pm
Reed, you’ll have to setup a Disallow in your robots.txt file.
If you put all of your redirect scripts into a single folder (or if you just have one redirect script), then you can use something similar to the following:
User-agent: *
Disallow: /myredirects/
Checkout http://www.robotstxt.org/ for more info.
Bill said
on April 20 2007 @ 3:24 pm
Great tips, thanks for the info!
Ryan J. Parker said
on April 26 2007 @ 10:02 am
Bill, I hope you find them useful!
moshu said
on June 2 2007 @ 1:04 am
Your PHP code works well… almost.
I have an affiliate link which has an image code in it for a 1×1px “invisible” identifier - after the anchor. Where would you include that in the above PHP code?
Thanks!
Ryan J. Parker said
on June 2 2007 @ 9:33 am
moshu, that image identifier shouldn’t be placed in the PHP used to redirect to the affiliate, it should be placed after the link to the affiliate redirect.
Patches and Hacks said
on September 18 2007 @ 5:38 pm
If you’re using wordpress you might want to look into my the new plugin that will let you manage such hidden links from your wordpress admin, without having to write any code.
Here’s a link to it: http://patchlog.com/wordpress/hidden-affiliate-links/
… oh and it’s free..
Mike said
on October 11 2009 @ 4:41 am
You can earn with us up-to $10 for every customer - http://monitor.mazecore.com/register_affiliate.php
used tires said
on January 6 2010 @ 5:32 am
Had I paid $7 for this type of information I probably would have been mad hehe, thanks for saving me $7 =D
Till then,
Jean
Comment RSS · TrackBack URI
Leave a comment
Pingbacks/Trackbacks
Pingback on May 19 2008 @ 4:39 am