Tag Archives: URL shortening

Make your own link shortener

Why you should do that?

First of all what’s a link shortener? Such online software exists and it’s widely used by the customers. Sites like bit.ly became extremely popular because of the growth of web apps like Facebook and especially Twitter. The simple goal that they achieve is to convert a long website uri into a short unique one. Beside that they give more information about who clicked that link and some useful stats along with that.

The question is why to make your own link shortener? One of the main reasons why is to paste links containing in plaintext your domain. In the case of http://stoimen.com instead of using http://bit.ly/xxxxx it will be great if the link was something like http://stoimen.com/xxxx than pasting it into Twitter or wherever I get the primary impression of my domain.

How to …

It should be no mystery how to make your own. In fact you’ll need only one more table into the database, as this is the most common way to achieve it. Of course you can do that with no database using the file system to store the hash table in whatever format you’d like.

In the case of the DB solution you can simply make a table with three columns containing the unique id of the row, the short and the full link. Thus requesting some short link the db will return the “real” full uri. You can simply drop the short column if you’d like more efficient solution. Thus the unique identifier may become short link. That may be really fast if you’ve an index on the full link column.

See the example below:

id | short_link | full_link
1  | qwrt 	| /blog/2010/01/27/theory-of-caching-zend_cache-zend-optimizer