{ Hi! I'm Mike }
I'm a core developer with The Horde Project and a founding parter of Horde LLC - the company behind the world's most flexible groupware platform. This is my personal blog full of random thoughts about development and life in general.
February 3, 2008

Lighttpd configuration specific to Horde

I've been using the Lighttpd webserver for about two years now, having switched over from Apache when I moved to a hosted VPS account and conserving memory became paramount. I've had a pretty messy collection of rewrite rules and aliases in my lighttpd.conf file to enable "Pretty URLs" in applications such as Wicked and Chora.  After recently adding similar functionality to Whups, Horde's ticket tracking application,  I  went through  my lighttpd.conf file and started cleaning it up. 

In the process of cleaning it up, I put together a collection of all the rules I've written specific to my Horde installation.  Horde already includes the necessary .htaccess files to implement this stuff, but since lighttpd doesn't support them (or any directory level config files for that matter) they need to be ported to lighttpd-style configuration directives.

The entire example file can be downloaded here, but keep in mind that you probably can't just use an 'include' directive to include it...especially if you already have some custom alias or rewrite rules already.  In that case, you will need to append most of these entries to your existing configuration directive.

To start with, Horde denys all access to files in various template and library directories by .htaccess files placed in those directories.  You can add something like the following to your lighttpd.conf file to accomplish the same thing:

$HTTP["url"] =~ "(/templates/|/s­cripts/|/lib/|/po/|/locale/|/config/)" {
    url.access-deny = ("")
}

This prevents browser access to anything in those directories. 

As I stated above, a number of Horde's applications can accept "Pretty URLs." As an example of this, you can visit Horde's own bug tracker at http://bugs.horde.org­. This will give you a search page where you can execute a search.  However, if you know that your looking for an issue in, let's say, the Ansel application, you could type http://bugs.horde.org/queue/ansel  and that would give you all open tickets for Ansel.

To implement that bit of magic, support in code is not enough, we also need to create rewrite rules so the server knows what page to direct those requests to.  In lighttpd, you accomplish this with the url.rewrite directive instead of Apache's Rewrite directive. For the example above, the entries look like this:

url.rewrite = (
    ## For Whups - pretty URLs for slugs
    "^/horde/whups/queue/([0-9]+)/?$" => ­"/horde/whups/queue/index.php?id=$1",
    "^/horde/whups/queue/([0-9]+)/rss/?$" => "/horde/whups/queue/rss.php?id=$1",
    "^/horde/whups/queue/(a-zA-Z0-9_]+)/?$ => "/horde/whups/queue/index.php?slug=$1",
    "^/horde/whups/queue/(a-zA-Z0-9_]+)/rss/?$ => "/horde/whups/queue/rss.php?id=$1"

)

The url.rewrite directive can only be used once in the config file, so these entries must be appended to any existing entries you may already have in the directive's array. 

There are examples for Chora, Whups, and Wicked in the example file. 

­