Short URLs

Fabien Potencier

March 06, 2009

Websites like Twitter makes URL shortener services a must. Basically, they convert long URLs to shorter ones by assigning a mostly unique hash:

The service for example converts this URL to this shorter one

My main concern with URL shortening is that you loose all the meaning embedded in the URLs. What does css7s5 refers to? Nothing. It is just a hash of the original URL. It is also very difficult to remember a short URL.

I wanted a shortener URL service that gives short URLs, but also keep some sort of meaningful information about the original URL. The solution was to implement my own little URL shortener service, specialized for my needs.

The first thing I did was to register a short domain name: (sf meaning symfony here).

Then, I simply configured rewriting rules for the short URLs I wanted to have:


  RewriteEngine On
  RedirectMatch permanent /bookmarks
  RedirectMatch permanent /answers
  RedirectMatch permanent /delicious
  RedirectMatch permanent /dailymotion

  # ...

The short URL for the above example is now:

Of course, if I start needing more short URLs, I will probably write a small PHP script. But for now, it gets the job done.