Categories

Archives

Did You Know?

My online gaming habit actually helped me land jobs. I used to run a web site and built web-based tools for a game called "Starsiege: Tribes".

Recent Comments

Tags

asp audio browser bug business coalesce code crash Database db debian extension framework imap internet legions linux metaverse mysql obscurity patch PHP postgresql properties release scp Second Life second life security session social media sound sql ssh subversion tables tortoisesvn tribes ubuntu virtual world web windows zend zend framework zf

Implementing short URLs using case-sensitive Routes with Zend Framework

Since short URLs are all the rage these days, I wanted to outfit one of my websites with its own short URL capability.

A simple way to accomplish this is to base62 encode a numeric identifier (the database table's primary key). In order to identify a URL as a short URL, it will be prefixed with an uppercase 'S'. So, a short URL would be something like this: http://mixoom.com/Snfup8.

With regular expressions it's simple to turn off and on case sensitivity using (?-i) and (?i) respectively. So ultimately the new route needed in order to accomplish mapping the short URL is the following:

$route = new Portal_Controller_Router_Route_Regex(
    '(?-i)S([\w\d]+)',
    array('controller' => 'photos',
          'action'     => 'shorturl'),
    array('shortid' => 1)
);

Write a comment