Turn GitHub into a URL shortening service

URL shortening services like TinyURL or Bitly have long since become a staple of the modern web and are popular enough that even Google has already killed theirs. Creating your own shortener is also a fun exercise, and at its heart it doesn’t require much more than a nifty domain name, some form of database to map URLs to, and a bit of web technology to glue it all together. [Nelsontky] I thought you didn’t even have to build most of them yourself, but you can just (ab)use GitHub for that.

Use GitHub pages to host the URL shortening website itself, [nelsontky] actually reuses GitHub’s issue tracker to map the shortened id to the original URL. Each redirect is simply a new issue, with the issue number serving as the shortening identifier and the issue title text storing the original URL. To map the request, a bit of JavaScript extracts the problem number from the request, looks it up through the GitHub API, and if a valid number was found (and API rate limits weren’t exceeded), redirects the caller accordingly. What’s particularly clever about this is that GitHub pages generally only serve static files stored in a repository, so all the redirect logic is actually placed in the 404 error handling page, allowing requests to any arbitrary path.

While it might not be as simple as putting all of your website content directly into the URL itself, it could be combined well with this rotary phone to simply dial the problem number and access your bookmarks – perfect in case you’ve always wanted your own website phone book. And if you don’t like the idea of ​​interacting with the GitHub UI every time you want to add a new URL, try command-line tools.

Comments are closed.