Shockingly simple URL shortening

URL shortening is something that's been at the back of my mind since listening to SitePoint Podcast #24 which discussed the near closure of tr.im.

Why are short URLs required? Twitter. Tweets are limited to 140 characters, and URLs often seem recklessly long in this context. Of course, Twitter could simply allow us to apply short, meaningful labels to our links as we've been doing in HTML for years. Instead, each time one includes a link in a tweet one must either:

  • spend a large number of characters on the full URL; or
  • use a short URL generated by a service such as bit.ly

I'm opposed to short URLs for several reasons. First, I believe that every reference to a resource should use that resource's Uniform Resource Identifier (if it has one) in its normalized form. In other words, we should not use http://www.wikipedia.org/ to refer to http://wikipedia.org/, and we should certainly not use http://bit.ly/8RTk. Having multiple URLs for a resource is a maintenance nightmare (unless one is willing to accept URLs being temporal).

Secondly, I have a simple rule: meaningful > meaningless. Meaningful markup is wonderful, and meaningful URLs offer similar benefits (to both people and search engines).

Finally — and this point relates to URL shortening services rather than to short URLs themselves — there's no guarantee that sites which currently provide a service will continue to do so indefinitely.

Enter John Gruber

I noticed one day that Daring Fireball now has its own shorturls, using the incredibly cool domain name ✪df.ws. This got me thinking that perhaps I should procure a short domain name and do something similar. Well, last week I did.

With dċd.ws safely registered in my name I began looking for an open source URL shortener to run on that domain. I then struck upon a simple, elegant solution which took all of ten minutes to implement.

RewriteEngine On
RewriteRule ^(.*)$ http://davidchambersdesign.com/$1 [R=301,L]

The code above forms the entirety of the .htaccess file on the dċd.ws server. All it does is redirect every request to the corresponding davidchambersdesign.com URL. The key word being every. As a result, existing pages on this site gained short_er_ (though not necessarily short) URLs automatically, and new pages gain a short URL the instant they are published. No maintenance, no fuss. Nice!

So, for example, http://dċd.ws/twitter/http://davidchambersdesign.com/twitter/ (a 17 character saving).

If you're interested in acquiring your own short domain name, I suggest trying .ws as it's one of the few top level domains to allow virtually any Unicode character in its domain names. As a result, there are plenty of short .ws domain names available. I don't suggest this approach for normal use, however, as browsers will display something like http://xn--dd-7la.ws/ in their address bars.