Sep 30 Make Your own TinyURL Service Written by: Curtiss |

centernetworks.pngtwitter.png

I was reading an article on CenterNetworks the other day, and it got me thinking. The article was about Twitter using a service like TinyURL to shorten all links posted on Twitter. The point Allen made was that, by doing so, Twitter was completely at the mercy of TinyURL’s server, and, if the TinyURL site ever went down for any reason (or, God forbid disappeared entirely) Twitter would be up the creek without a paddle (paraphrasing there). He pointed out that Twitter really ought to develop a URL-shortening service of its own, rather than relying on TinyURL.

As I said, that got me thinking. Why hasn’t Twitter developed its own URL-shortening service? What’s so difficult about it?


I’ve always kind of wondered - how does TinyURL make any money? I’m sure, with over 47 million URLs that have been shortened, the TinyURL server must have to put up with at least a slightly above-average amount of bandwidth (which isn’t cheap, as you all probably know). Is all of the site’s income based strictly on donations?

I’m also curious - what’s so special about TinyURL. The way I see it, I think it would probably take about 15 minutes to write a script that would do the same thing it does, and another 15 minutes to design and implement a much nicer site through which the users would shorten their links.

All you need is a database and a server-side language. Grab the full URL from a form (like TinyURL does) and query the database to see if that URL’s been entered before. If it has, you pull the alias you’ve already generated and return that. If it hasn’t, you generate a random number, encrypt it using something like md5, shorten it to 6-8 characters, check to make sure that alias has not been used before, place it in the database alongside the real URL and then you’re more than halfway there.

From there, you simply use ht rewrite (or something similar) to give yourself the permalink URLs that they offer, and have all of them redirect to index.php (or index.asp or pl or cgi or whatever server-side language you want to use) with a query string showing the random, encrypted number that coincides with the URL. Then, query the database for the real URL that matches up with that number and put the database result inside of a header redirect (Response.Redirect or header(”Location: $myresult”) or similar).

Bam! You’re done. You’ve got your very own TinyURL service. If you want to make money off of it, then, instead of using a redirect script, you simply load the real URL inside of an iFrame and place a random advertisement somewhere on your home page.

Sure, it might take a bit longer to get secure widgets and everything designed so that users could automatically generate shorter URLs the way Twitter does, but that shouldn’t stop someone from trying. In Twitter’s case, if they were going to use the service completely in-house, there wouldn’t really be a need for that. If you aren’t going to let someone send queries across servers, then you don’t need secure widgets that allow GET queries to run. Everything can be done through secure POST queries if you write it correctly.

You could even make money off of it by building in small advertisements that would automatically display on the page that you’ve redirected to.

There is really no excuse for Twitter not developing and utilizing its own service for this purpose.


3 Responses to “Make Your own TinyURL Service”

  1. K Says:

    Your save-process is too complicated. You don’t need to create a hash. Just increment the id by one for each URL. And then you use one of the smart “character to decimal” converters out there, that converts base87 (or whatever) to the internal numerical value.

    Much more simple, and you avoid checking for duplicates. The first users of your service also gets 2-3 letter id’s, so that makes it more attractive.

  2. sburton Says:

    Good info well i run a urlshorting service i found this when i was researching the comption as my site is very new but doing ok as not done much promting on as of yet. Why i made this site well to offer a free service to web masters and i did not like the sites i use to use when i made small er urls the server cost are not cheap unless you have a decicated server as i have that way i can run my own sites with out much cost at all

  3. SEO Consultant Says:

    I prefer http://www.tiny9.com because you can specify tags to use in your URLs instead of generating random ones.

Leave a Reply

KickApps
Clicky Web Analytics

community discussion