Easy Guide To Create Your Own URL Shortener

Since Twitter launched in 2006, shortening URLs to squeeze into that 140 character limit has become a popular pursuit. There are many URL shorteners out there already; I’ve always used Bit.ly by default and never had any issues. But then, I’ve started to see more and more custom URLs being used by various people. Techcrunch has http://tcrn.ch, Dave Naylor/Bronco have http://bro.gs, Malcolm Coles has http://mcol.es and so on. So I thought to myself “that seems pretty cool” (well as cool as URL shortening can be anyway) and decided to have a go myself….

Short Links!My first stop was Bit.ly Pro as I remembered reading about it not so long ago. But, it’s still in beta and although I’ve no doubt it works well, I think they’re only accepting popular sites/bloggers at the moment. I filled in the form and didn’t hear anything…. it might be an option for you, but not me.

So, hosting my own shortener seemed to be a good alternative. Of course, the main reason to get a custom URL shortener for a lot of people is purely down to vanity (can I say that? Oh well, too late) but there are other advantages to hosting your own. These mainly revolve around being more in control of your link data, which is never a bad thing.

The main requirements for me were pretty simple:

  • Must be easy to set up (I’m “tech” but “busy”)
  • Must integrate with WordPress
  • Must also integrate with my Tweetmeme button

I have a tech background so I’m naturally lazy a huge fan of not recreating the wheel. My first stop therefore was Google to see what I could see. I stumbled upon this post on Outspoken Media which describes how to use a shorter URL on your existing blog domain. Well, everyone in the comments section seemed to love the idea (hey, they know what’s good for them) but it’s not really what I’d call a solution. Next up I saw a post by Sean O which describes how to write your own URL shortener from scratch. Now look, I could write my own PHP/MySQL shortener but for the purposes of what I’m trying to achieve, it’s not really worth my time.

But fear not as I did manage to come up with a solution in the end that met all my criteria, without requiring too much effort. So click to get to part 2 and I’ll take you through step by step :)

This entry was posted in Code Snippets, General.

21 thoughts on “Easy Guide To Create Your Own URL Shortener

  1. Pingback: Tweets that mention Easy Guide To Create Your Own URL Shortener -- Topsy.com

  2. So, I’m using Bitly Pro as you say. How do you hack tweetmeme if you’re doing that – presumably you put something else in:
    $shorturl = get_post_meta($post->ID, ‘yourls_shorturl’, true);
    Any idea what? I couldn’t find any documentation on the tweetmeme API alias.

    • I’m not sure on code for that, sorry. I’ll have a think and see if I can figue it out. Just to check, are you running the latest version of the Tweetmeme plugin (1.8.5)? I know 1.8.4 and 1.8.5 added more support for Bit.ly Pro and fixed the issue of not being able to save your API key if you selected Bit.ly as an option on the Tweetmeme admin page.

  3. Hi Jon, very useful post! But “Stage 4 – Change YOURLS short URLs (Optional)” doesn’t seem to work in YOURLS V 1.5. In this version functions-baseconvert.php is missing.
    Do you happen to know a solution?

  4. Pingback: Yourls 1.5 Shortened URL Length Hack « Sandy Dolphinaura

  5. I i just want to leave a simple comment to state your weblog was good. I came across it on yahoo lookup right after going through a great deal of other information that has been not really relevant. I was thinking I might come across this much earlier considering how excellent the content is.

Comments are closed.