Technology: How do tinyurls work?

Ssh! I know the secret. Now you are about to know the secret. Read on; if you can you keep a secret.

tinyurl
tinyurl-split

Operation tinyurl.com
Once I got the opportunity to look behind the closed doors of tinyurl.com. It was highly dangerous. A split second’s mistake, I am done for. Anyway, I took the chance. And do you know what I saw? A goat!
Yes, a goat is their secret. The long urls are fed to the goat which chews and chews and chews it until it becomes a tiny URL. It is then picked up by an employee who posts it on the internet. That’s how tinyurls work.
Jokes apart the charm of tinyurls stop the moment you tame the beast. The beast is called – metarefresh. Let’s say hello first.
Meta refresh
Meta refresh is a part of Meta tags. They are called Meta because they provide structured data about a web page, particularly to the search engines.
<meta name=”description” content=”A blurb to describe the content of the page appears here” />
Meta tags are placed inside <meta> tag as shown above. There exist two more valid Meta tag in addition to the ones listed above– scheme and http-equiv. Of which, http-equiv will help us understand how tinyurls work.
How to redirect a page?
Would you believe me when I say all it takes is a single line?
Here is the magic line.
<meta http-equiv=”refresh” content=”0;url=https://designpuli.com”/>
This line instructs the browser to redirect to https://designpuli.com immediately. The zero inside content makes the redirect instant.
How does tinyurl.com use this?
When analysed closely, you can see that there are two parts for a tinyurl – a base part and a random part. Like this:

This tinyurl redirects you to “www.designpuli.com”

“ptl29z” is the name of a folder (unique name randomly generated), that resides inside the root of “tinyurl.com”, with a single file called “index.html” containing the following data.

<html>
<head>
<meta name=”description” content=”redirecting to the following url”/>
<meta http-equiv=”refresh” content=”0;url=https://designpuli.com”/>
</head>
<body bgcolor=#ffffff>
</body>
</html>

What does this leave you with?
Nothing. Except an idea to make a fortune. Tinyurl.com has grown from mere redirection to toolbars, APIs and more. If you have the shortest URL in the world, well, this is your game.


Epilogue : Eventhough tiny urls can be interesting, there has always been an ongoing debate upon its shady nature. In this Blogoscoped article, the pros and con are discussed in detail.