The Personal URL Shortener, Revisited

Back in 2013 I wrote shrtn, a super-simple Personal URL Shortener that I've been using happily ever since. As I wrote back then:

[It's] a simple perl script that captures (or generates) a mapping
between a code and a URL, records it in a simple text db, and then
generates a static html file that uses HTML meta-redirects to point
your browser towards the URL.

This has a few features I really like:

  • It's a command line utility that is just a git clone away on any linux or mac box, so it's portable and private (no web interface that I have to authenticate to use).

  • New slug => url mappings are automatically captured to git and can be pushed to multiple remote repos for backup e.g. github.com.

  • It can handle custom slugs (so ofn.me/shrtn, for instance), or it can generate random slugs for you.

The fact that it uses HTML meta-redirects lets you use any simple static web hosting you like - no dynamic content support (PHP, javascript etc.) is required.

That said, there are a few drawbacks with the HTML-META-redirect approach:

  • HTML META redirects work well with real browsers, but spiders and bots tend not to handle them. (This may be a feature, of course, depending on your point of view.) It would be nicer to use proper HTTP redirects instead, though.

  • Static webspace is cheap, but it's not free, and it's not trivially simple to setup and configure. There are plenty of providers that will give you a small VPS for $5/month that will do just fine for this, but that's still $60/year, and there's still the work of actually configuring a webserver properly and copying the html pages up, etc.

  • The web has moved on in the last 5 years, and there are now lots of interesting "cloud" options available that give us a lot of functionality for less, and are perhaps simpler to setup and maintain because they do more of the heavy-lifting for us. We can do better! :-)

My Personal URL Shortener

I wrote a really simple personal URL shortener a couple of years ago, and have been using it happily ever since. It's called shrtn ("shorten"), and is just a simple perl script that captures (or generates) a mapping between a URL and a code, records in a simple text db, and then generates a static html file that uses HTML meta-redirects to point your browser towards the URL.

It was originally based on posts from Dave Winer and Phil Windley, but was interesting enough that I felt the itch to implement my own.

I just run it on my laptop (shrtn <url> [<code>]), and it has settings to commit the mapping to git and push it out to a remote repo (for backup), and to push the generated html files up to a webserver somewhere (for serving the html).

Most people seem to like the analytics side of personal URL shorteners (seeing who clicks your links), but I don't really track that side of it at all (it would be easy enought to add Google Analytics to to your html files to do that, or just doing some analysis on the access logs). I mostly wanted it initially to post nice short links when microblogging, where post length is an issue.

Surprisingly though, the most interesting use case in practice is the ability to give custom mnemonic code codes to URLs I use reasonably often, or cite to other people a bit. If I find myself sharing a URL with more than a couple of people, it's easier just to create a shortened version and use that instead - it's simpler, easier to type, and easier to remember for next time.

So my shortener has sort of become a cross between a Level 1 URL cache and a poor man's bookmarking service. For instance:

If you don't have a personal url shortener you should give it a try - it's a surprisingly interesting addition to one's personal cloud. And all you need to try it out is a domain and some static webspace somewhere to host your html files.

Too easy.

[ Technical Note: html-based meta-redirects work just fine with browsers, including mobile and text-only ones. They don't work with most spiders and bots, however, which may a bug or a feature, depending on your usage. For a personal url shortener meta-redirects probably work just fine, and you gain all the performance and stability advantages of static html over dynamic content. For a corporate url shortener where you want bots to be able to follow your links, as well as people, you probably want to use http-level redirects instead. In which case you either go with a hosted option, or look at something like YOURLS for a slightly more heavyweight self-hosted option. ]