The Incredible Shortlink Technology Page of Doom (TM)


To set up your own shortlink thingy there are a few pre-requisites that you will need:

Grab the source code, untar it, and cd into the newly created shortlink-0.2 directory. You'll need to create a database, and a user with permissions to insert and select on the table we'll create. To do this with mysql, enter the following commands:

mysql -u root -p
create database shortlink;
grant select, insert on shortlink.links to 'user'@'localhost' identified by 'password';
flush privileges;

This assumes you have root permissions on the database in question - if you don't, you will need to check with your hosting providers documentation on what username/password/database to use.

Next, you need to create a table for the links to be stored in. To do this, type the following:

mysql -u root -p shortlink < shortlink.mysql.sql

Use the file if you're using postgres.

This will create a table called 'links' in the shortlink database, using the SQL create table command that's in the shortlink.sql file.

Now, load up the shortlink.cgi file in your favourite editor and change the database connection details to whatever you used when you created the database, and change the base shorturl to suit wherever you're installing it.

Finally, you'll need to make the script executable. To do this, type:

chmod 755 shortlink.cgi

Now you should be able to open a web browser, and point it at your shortlink script. If all has gone well, then you will get a text box to enter your long URLs in.

That's it?

Yup. If you want to make your shortlinks even shorter, you can use the script as the index file in a directory, as I've done with It's cheating a bit, but by creating a directory with a short name, and renaming the shortlink.cgi to index.cgi then you can ignore the filename of the script, assuming your web host supports index.cgi as an index page.

Advanced fun

Those of you who happen to run apache can use the ever funky mod_rewrite to make creating shortlinks from your own website even simpler. Make sure you have mod_rewrite enabled, then add the following lines to your apache config file:

RewriteEngine On
RewriteRule /(.*),shortlink$1  [R]

The first domain in the rewrite applies to the script location - in this case The second is the domain for which the shortlink shortcut applies. Assuming a setup like this, you could go to,shortlink and it will auto generate a shortlink for you.