Create TinyURL at Your Site and Shorten Long / Affiliate Links

Many web masters and bloggers prefer to hide the affiliate links from their web pages, partially to hide the affiliation link from their visitors and also to easily change the affiliate links. Your visitors trust links from your own domain than a tinyurl link. You could use HTTP meta redirect, JavaScript redirect or .htaccess redirect to redirect to the external link.

John has written in detail about the HTTP-EQUIV and JavaScript based redirection technique to hide affiliate link. In this method, You will have to create an HTML page and upload it to the server for each of your affiliate/short link, which is difficult. Moreover, such redirects are not preferred by Search Engines.

Editing .htaccess file is not possible always in shared hosting and its difficult especially dealing with RegExp. Your modifications to the .htaccess could affect the whole website/directory when there is some error in the file, which happens often.

I would rather suggest another simple script based solution. You could create your own TINYURL links from your website using scripts like PHP, ASP, etc.. You may encapsulate your affiliate links, or long URLs into short URLs hosted in your own website. You will never have to depend on the tinyurl services anymore!

I have created a folder and saved the below script as index.php. Add the long URLs and the short codes to the array in the PHP code. For example, redirects to Google Apps affiliate link, and redirects to this post.

Whenever you want to add a new item, just edit the index.php and add a new item to the array for a new long or affiliate URL. If you are tech savvy, you may also use an XML to save the long URL and short code, and use XML parser, or you can even save to the database. I just want to keep it simple, but effective.



$request=strtolower(substr($_SERVER["QUERY_STRING"], 0));

if(array_key_exists($request,$arrMoved)) {
    $headercode = "HTTP/1.0 301 Moved Permanently";
    $headerloc = "Location: ".$newurl;
} else {
    $headercode = "HTTP/1.0 404 Not Found";
    $headerloc = "Location:";

header("Connection: close");

Be the first to comment

Leave a Reply