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 teck.in/t/ 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, https://teck.in/t/?gapps redirects to Google Apps affiliate link, and https://teck.in/t/?tiny 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.

[advt]

<?php
$arrMoved=array(
	"tiny"=>"https://teck.in/create-tinyurl-at-your-site-and-shorten-long-affiliate-links.html",
	"gapps"=>"http://pagead2.googlesyndication.com/pagead/iclk?sa=l&ggladgrp=428067339&gglcreat=603588159&adurl=http://www.google.com/a/%3Futm_campaign%3Den%26utm_source%3Den-asref-ww-ww%26utm_medium%3Dasref%26utm_content%3Dtext_v4&client=ca-ref-pub-8709410846673588"
);

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

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

header($headercode);
header($headerloc);
header("Connection: close");
exit();
?>

Be the first to comment

Leave a Reply