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 tinyurl.com service for example converts this URL http://www.symfony-project.org/blog/2009/02/18/dailymotion-powered-by-symfony to this shorter one http://tinyurl.com/css7s5.

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-to.org (sf meaning symfony here).

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

<VirtualHost *:80>
  ServerName sf-to.org
 
  RewriteEngine On
  RedirectMatch permanent /bookmarks   http://www.symfony-project.org/blog/2006/10/28/yahoo-bookmarks-uses-symfony
  RedirectMatch permanent /answers     http://www.symfony-project.org/blog/2008/05/08/yahoo-answers-powered-by-symfony
  RedirectMatch permanent /delicious   http://www.symfony-project.org/blog/2007/10/02/delicious-preview-built-with-symfony
  RedirectMatch permanent /dailymotion http://www.symfony-project.org/blog/2009/02/18/dailymotion-powered-by-symfony
 
  # ...
</VirtualHost>
 

The short URL for the above example is now: http://sf-to.org/dailymotion.

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.

Discussion

gravatar Padraic Brady  — March 06, 2009 20:01   #1
http://www.short.ie 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 sf-to.org (to symfony or to this page) instead of this not allowed page.

Regards,
Nathan
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
El32.com shortens urls even further. Try it

http://el32.com