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:

<VirtualHost *:80>
  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.


gravatar Padraic Brady  — March 06, 2009 20:01   #1 allows for adding custom terms in short urls - might be worth a look for those needing more meaning in their shortened URLs.
gravatar Nathan Bijnens  — March 27, 2009 12:25   #2
Adding an index to (to symfony or to this page) instead of this not allowed page.

gravatar Pete Nicholls  — March 28, 2009 21:48   #3
TinyURL, probably the most popular URL-shortener (and the one you use in your example), lets you specify a keyword instead of a random string. It's the field directly below the URL field.
gravatar sandra  — April 15, 2009 17:32   #4 shortens urls even further. Try it