snippy urls
Posted by ark, ,
I really like the idea of being able to make nice small urls from really big ones like you can with snipurl.com but of course their keyword namespace is all used up. So I wrote my own. The intention is that you put it as the 404 error document for your server and when someone goes to yourdomain.com/keyword this picks that up and sees if it's in its map and if it is redirects you. You add urls using a cgi prameter which is very easy to do with Mozilla keywords. The database is a regular old ini file which php is o.k. about parsing. Since you probably don't want everyone filling up your namespace with their keywords, adding keywords is either protected by an IP address white list, or failing that a simple user name/password setup. It's all very basic, but it works and I'm happy with it at this point so I'm putting it up here. At a future date I might put in some kind of keyword management so you can see all your keywords and perhaps trim them down, but right now it's easy enough to just edit the config/db file by hand.

While writing this the biggest frustration was dealing with the config file. I tried to use the pear config module it was uber frustrating. It just wasn't easy to have an object I can load, get settings from, add settings and save. So I gave up, used the built in parse_ini_file which was super simple and is built in. Since my [urls] section is at the end I can add urls just by appending to the file.

So here it is: your very own url shortening code.

I guess I should have used snippy urls for the links in this post eh?

Update: 2006-12-25: I just changed the code that displays the snippy url to have it be in a text input, pre focussed and pre selected so you can just control-C when the page loads and it's in your clipboard. The form's action is the snippy url (via post) so you can hit enter to test your new snippy url.

Update: 2008-08-10: I made it so you can use the same mozilla keyword to add a url as you can to choose a url. I use the keyword 'w' so I can type "w cnn http://cnn.com/" in mozilla to create a snippy url. Then I can type "w cnn" to access that url. 'w' is a mozilla keyword to 'http://example.com?kw=%s'

Update 2010-04-11: this code has been superseded by an App Engine implementation. Described here.

Comments

Posted Sunday 20 August 2006 Share