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:
- 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.
- 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.
- 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.
- 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|
|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.
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.