View on GitHub

twtr.io

Algorithmic Twitter URL shortener

twtr.io is an algorithmic URL shortener for Twitter URLs.

Given a full URL to a tweet such as https://twitter.com/aaronpk/status/364781641031360514, this can be shortened to http://twtr.io/bBowYg3hMu. When the short URL is requested, it is algorithmically expanded to a twitter.com URL. Since the shortening is done algorithmically, no database is needed, and the requirements for running this code are very small.

Try it Now!

Tweet URL:

Shortening

The base 10 tweet ID is converted to a NewBase60 number to compress it. The ID is appended to http://twtr.io/ forming the shortened URL for the tweet.

Un-Shortening

To un-shorten a link, the NewBase60 number is converted back to its base 10 equivalent. The base 10 ID is appended to https://twitter.com/_/status/. This takes advantage of a feature of twitter.com where they will redirect a tweet URL to the correct username.

FAQ

Q: Why do I need this?

A: You probably don't

Q: Where is this used?

A: You can see an example of where this is useful on the IRC logs for the #indiewebcamp IRC channel.