Run your own damn URL shortening service
Oct. 13th, 2009 09:06 pmTired of tinyurl? Worried that whatever other shortening service you're using might go away one day? Want to get yourself a little more autonomous? Here's how to run your own damn URL shortening service, in three easy steps.
If you don't like the idea of people being able to list all your shortened links, change the filename to something other than "shorten.txt" and the
That's all.
- This is slightly more interesting if you have a short domain already, like rhmt.org.
- This is a string-and-chewing-gum system you can set up in two minutes, and it's clearly not going to scale well if you have thousands of URLs to shorten; by that time, you can replace it with something heavy-duty.
- We are also banking on the fact that you don't have any valid URIs in your domain which entirely consist of capital letters (http://example.com/WOMBATS).
- stick this PHP script in the root of your website. (I'm not a big PHP fan, but you know it'll work anywhere.)
- create a file "shorten.txt" with the URLs you want to shorten in it, one per line. Put that in the same directory.
- edit your Apache httpd.conf and add the lines
RewriteEngine on RewriteRule ^/([A-Z]+)$ /shorten.php?u=$1And restart Apache. Now go to http://example.com/shorten.php?list=1 and you will see a list like this:
http://example.com/A http://www.gnome.org http://example.com/B http://borrowable.net http://example.com/C http://shavian.org.uk/xkcd/The links on the left will then go to the destinations on the right. Just edit shorten.txt to add some more.
If you don't like the idea of people being able to list all your shortened links, change the filename to something other than "shorten.txt" and the
if ($_GET['list']) {to check for some other parameter that only you know.
That's all.