Home > Review > Host Your Own URL Shortener: 10 PHP Apps Reviewed

Host Your Own URL Shortener: 10 PHP Apps Reviewed

Shorter URLs

I have been planning to host a personal tinyurl or bit.ly like URL Shortening service on my website.  I was going to write my own software for this, but thought I’d start by reviewing some existing PHP Apps just in case one already met my needs. I wanted to add a URL shortener to my website for a couple of reasons:

  1. People don’t always trust blind redirect links from tinyurl or bit.ly.  If the links came from my website, people would know the links were somehow related to my site and that I considered them safe.
  2. To shorten links sent over email, but still append a small path to them so people have some idea what they’re clicking on.  For example, assume http://esev.com/Fga34A was a shortened URL that pointed to a Google Map of my house.  I’d like to be able to append /MyHouse to the end of the link (i.e. http://esev.com/Fga34A/MyHouse) without that breaking the redirect.  This is not easily possible with most URL shortening services.
  3. To also use the shortener to create custom landing pages for my website.  I’d like to keep my domain name in these landing pages and also be able to customize the name of the short URL.  Hosting the URL shortener on my site enables me to pick any name I’d like for the short link, without worrying whether someone else already reserved it.  These landing pages are handy for adding Google Analytics custom campaign tracking tags so I can tell which sites are linking to my blog posts.
  4. To have the ability to use regular expressions to create dynamic URLs to the destination page would be nice too especially for Amazon affiliate links.  These require you to add an /affiiliateID to the end of the URL.  A regular expression could take the path passed to the short URL and generate the long URL.  For example, I’d like something like this which you get with mod_rewrite:
    Link: /amazon/([^/]+)
    Destination: http://amazon.com/exec/obidos/ASIN/$1/ref=nosim/affiliateId

The table below lists the URL shorteners I reviewed and compares them to the features I was looking for.

Name Random link Custom link Append URI Regex Has API Redir Type Private Custom title Edit Stand alone
Pretty Link Yes Yes Pass / Prevent Query String Yes 301 / 307 Yes Yes Yes No
YOURLS Yes Yes Prevent No Yes 301 Yes / No No Yes Yes
Link Shortcut Yes Yes Fail No No 301 / 302 Yes Yes Yes No
Simple Link Cloaker No Yes Pass No No 302 Yes No Yes No
GoCodes No Yes Prevent No No 301 Yes No No No
phurl Yes No Fail No Yes 301 No No No Yes
urlShort Yes Yes Prevent No Yes 301 No No No Yes
Shorty Yes Yes Fail No No 302 Yes No Yes Yes
TightURL Yes No Prevent No Yes 301 No No No Yes
Short URL Script Yes No Fail No No 301 Yes No No Yes
Last updated June 30, 2009

The columns indicate the features I was interested in and show if the URL Shortener supported that feature.

  • Random link - Does the software have the ability to generate a random link?  This is useful for automating tasks.  For example, if I wanted to post a short link to each blog post on Twitter, I would want the software to automatically generate a random link name.
  • Custom link - Does the software allow me to choose the name of my link?  Sometimes I do want to specify the name of the short link.
  • Append URI - Does the software allow data to be appended to the end of a short URL? For example, if the short link is http://esev.com/Fga3A and it points to http://www.google.com/, what happens when I type http://esev.com/Fga3A/analytics/?  Fail means the software could not handle that type of request and did no redirection at all.  Pass means it passes the extra URL data along when doing redirection – something that I did not want to happen.  Prevent means the shortener ignored the extra path and still forwarded to the original URL – which is what I wanted.
  • Regex – Does the software support regular expressions for mapping the path passed to a Short URL to the destination URL?  See #4 above for the reason behind this.  Only Pretty Link comes close to this, enabling the query parameters (stuff after the ? in a link) to be generated based on the URL.
  • Has API – Does the software have an API to support using it inside other software?  For example, if there is a really great plugin sending blog posts to Twitter, is it going to be easy to integrate the URL shortener software with this plugin?
  • Redir Type – What type of redirection does the software generate?  301 redirects are optimized out by search engines – which is what I wanted.  This post on URL Shorteners has a good description of the differences between 301 and 302 redirects. (It is also where I got the idea to make this table.)
  • Private – Does the software require an username/password for adding links?  Some of the software for URL Shortening is meant for public sites like tinyurl and bit.ly.  I’d rather be in control of all the links on my site.
  • Custom title – Does the software allow the user to enter a description of the link?  This can be useful later to determine the difference between two similar links (i.e. http://esev.com/a?q=1 and http://esev.com/a?q=2).
  • Edit – Can the destination link be changed after the short URL is created?  If the destination site changes, it would be useful to be able to modify the link.
  • Stand alone – Can the software be run on its own, without WordPress?  I’d like my blog to live in /blog on my website.  If the shortener is tied to WordPress then all my short links would need to include /blog in them – making them a little longer than I’d like.

Conclusion
In the end, I decided Pretty Link fit most of my needs.  The developer, Blair Williams, is also very responsive to questions and requests for new features.  I expect Pretty Link will continue to improve.  There were only two things Pretty Link didn’t satisfy; supporting regular expressions and being standalone.  Both of which I worked around with a few mod_rewrite Apache rules and a small modification to the Pretty Link source code.

In addition to the features I was looking for, Pretty Link includes a few extra features:

  • Optionally track the Number of Hits per link
  • Provides a reporting interface where you can see a configurable chart of clicks per day. This report can be filtered by the specific link clicked, date range, and/or unique clicks.
  • Can use the short URLs as Tracking Pixels and track impressions

Do you know of other URL Shorteners that might fit the solutions I need?  Or did I make any mistakes in the comparisons?  Leave me a comment and let me know.

Share

No related posts.

  1. June 30th, 2009 at 20:06 | #1

    Wow, Awesome! This is probably the most thorough article on self-hosted url shorteners I’ve seen. That’s actually the reason I wrote Pretty Link — I couldn’t find one that fit my needs. I just wanted to chime in on a few points in your great article:

    1. I never considered opening up regular expressions for forwarding parameters — what a brilliant idea! My query string is actually a simplification of regex params which I use on the back end. It actually would be pretty easy to add regex parameter forwarding! I’m putting it on my feature list now.

    2. You mentioned 301 redirects in your article — one of the beauties of having your redirects reside on your site is that 301 redirects aren’t as important! This is because a 301 redirect just forwards Google pagerank to the target page — this is important when using a service to link to your site because you don’t want bit.ly getting credit for your content. But with Pretty Link, it’s basically an alternate url to a page on your site and if you use canonical links on your pages then you get credit whether your using a 301 or 307 (or 302) redirect!

    3. I use 307 redirects which is a newer kind of temporary redirect … but when an old web client (using HTTP 1.0) accesses your pretty link, it will automatically degrade from a 307 to a 302 redirect.

    4. I’ve had a few requests to make this thing standalone and I’m considering it. It would be quite a bit of effort for me since Pretty Link is tied tightly with WordPress now — but you might just see a version like this in the future. Until then, I’d consider just installing a version of WordPress specifically for pretty link on your root and then your blog … I know that isn’t optimal but it would definitely work for you.

    Anyway — hope that wasn’t too much info :) — thanks for the great article!

    • July 1st, 2009 at 17:43 | #2

      Thanks for the clarification on the redirect types Blair! It makes sense what you said about the 301 redirects not mattering for your own domain.

      I’m very much looking forward to having regular expressions in a future release of Pretty Link!

      Thanks for the comment!

  2. July 9th, 2009 at 14:19 | #3

    Super post, Need to mark it on Digg

    Joker

  3. August 12th, 2009 at 00:18 | #4

    Thanks for including urlShort in your list! Private functionality is definitely on my list of things to add to urlShort, for those who want it. I'm a bit confused as to what you define as the difference between custom titles, and append URI… Don't they accomplish the same thing? And as far as editing in urlShort goes, it's something that I personally am opposed to (namely out of concerns of abuse), but that may eventually be an optional setting just to satisfy the needs of those who want it.

  4. August 13th, 2009 at 16:32 | #5

    Nice list, and great chart – quite useful.

    If you (or any of your readers) do decide to build your own URL shortener, it’s easy. I just posted an article on how to create one for your own site using PHP & MySQL.

    http://sean-o.com/short-URL

    At under 50 lines of code, it’s not intended as a “solution”, but might serve as a good jumping off point for those who like to tinker.

  5. September 10th, 2009 at 06:02 | #6

    I’d like to add that the GentleSource Short URL script allows custom links and has an API. :-)

  6. December 11th, 2009 at 23:28 | #7

    Many of folks write about this matter but you wrote down really true words.

  7. Vampie
    December 24th, 2009 at 07:38 | #8

    Hi,

    Just to let you know that Phurl now has an optional “Custom alias” option.
    (in the 2.0.0 beta)

  8. February 25th, 2010 at 11:45 | #9

    Sorry to butt in on this so far after the event: you didn't mention Shaun Inman's Lessn. It's basic, but not tied to WordWordPress and lightweight.

    • February 26th, 2010 at 06:05 | #10

      Donald,

      No worries, you're not butting in! I didn't know about Lessn at the time. I like how simple it is – not much to go wrong there. I'm not sure it would fit everything I was looking for at the time, but it'll definitely be worth adding to this chart when I get a chance to update it.

      Thanks for the comment!

      • thealanhogannetwork
        August 15th, 2011 at 15:07 | #11

        Lessn More is a Lessn fork that is just a bit less simple, with support for e.g. custom short URLs, case sensitivity, and shorter slugs.

  9. February 26th, 2010 at 00:50 | #12

    Which of these URL Shortener tools do you prefer ?

    http://answ.me/5kl7y9

  10. February 26th, 2010 at 00:58 | #13

    I am wondering what you did to make Pretty Link work stand-alone to support a different URL then your blogs one. Could you explain how you did this?

    • February 26th, 2010 at 05:54 | #14

      Frans,

      To things are needed for this:

      1. Modify pretty link's prli-config.php file. Change $prli_blogurl to be the root of your website. So, for mine, I set $prli_blogurl = 'http://esev.com';

      2. Use mod_redir to forward unknown top level requests to pretty link (actually to WordPress):
      RewriteEngine On
      RewriteCond /var/www/$1 !-f
      RewriteCond /var/www/$1 !-d
      RewriteRule ^([^/]+)(/.*)?$ /blog/$1$2 [PT]

  11. February 25th, 2010 at 21:00 | #15

    Lessn is great, albeit simple, plus it integrates with Mint.

  12. February 26th, 2010 at 01:00 | #16

    Lessn is great, albeit simple, plus it integrates with Mint.

  13. February 26th, 2010 at 06:00 | #17

    Thanks! Works like a charm (actually I already found out myself but your rewrite routing is better).

  14. February 26th, 2010 at 06:46 | #18

    Thanks for this comparison. I was looking for information about a.) what systems are out there and b.) what do they support. Your work saved me a lot of time.

  15. February 26th, 2010 at 08:27 | #19

    Great write up. I have been looking for an article that in PLAIN ENGLISH explained the best URL tools. Your chart and all helped out a lot as well. Now to just try a few of them out and see what ones end up working best for me. B)

  16. February 26th, 2010 at 08:53 | #20

    Thanks for this comparison

  17. March 12th, 2010 at 08:08 | #21

    Thankd for this compaduson;

  18. March 16th, 2010 at 10:44 | #22

    I'm a bit late in the discussion but that's an interesting comparison chart. As the YOURLS guy, I like to compare various solutions and see what features could make it into YOURLS. From what I see here the only real stand alone solution is, well, mine :-)

    The regexp support idea is pretty interesting. I see a number of potential issues, mainly security and user interface/ease of use, but I'll think about this.

  19. May 15th, 2010 at 15:40 | #23

    Are you tired of posting URLs in emails that the recipient has to cut and paste back together? I use http://paidly.com – url shortener

  20. tinjaw
    June 10th, 2010 at 12:53 | #24

    Thank you for doing all this work to post your findings. It was very useful.

  21. December 10th, 2010 at 05:11 | #25

    thanks for giving this valuable information as we know tiny urls are very beneficial for all websites as they perform multiple task like they manage links in a systematic way.They are transferable on social media services and most important they promote sharing.

  22. May 23rd, 2011 at 06:27 | #26

    Eric. Ive been using Yourls & it also has custom url options. Plz check .

    For me Yourls rock ! it comes with a wordpress plugin too which makes it my best choice

  23. thealanhogannetwork
    August 15th, 2011 at 15:12 | #27

    As maintainer of Lessn More, let me say that as of 2011-08-15, it would fit into the table thusly:

    Random link? Yes.
    Custom link? Yes.
    Append URI? No.
    Regex? No.
    Has API? Yes.
    Redir Type? 301. (I follow short URL best practices)
    Private? Yes.
    Custom title No. No title functionality currently. Would not be hard to add this feature (we're on GitHub, pull requests welcome).
    Edit? Yes, with a big fat warning that changing existing URLs may be Bad For The Internet™.

    Strips extra punctuation off the end of the URL (Bonus): Yes.
    (That means that e.g. http://ajh.us/1) does not fail but rather is treated as http://ajh.us/1 which would be a real redirection; this does happen in some email and Twitter clients.)

  1. No trackbacks yet.

You appear to have javascript disabled. If you'd like to leave a comment, please enable javascript for this site and for intensedebate.com