« Back to Posts

Wordpress, Lighttpd, and Permalinks

Jul 11, 2008

When setting up WordPress on Lighttpd it can take a little tweaking to get the permalink URLs right. And, of course, we want to use permalinks so that our URLs don't look like a string of swear words with &s, ?s, and /s.

Lighttpd is a wonderful webserver if you don't need all the power that lurks within the enigma that is Apache. (And don't even mention IIS to me, I don't want to hear about it.) But when setting up WordPress on Lighttpd it can take a little tweaking to get the permalink URLs right. And, of course, we want to use permalinks so that our URLs don't look like a string of swear words with &s, ?s, and /s.

My first resource was the WordPress Codex, which pointed me to this post. I couldn't get his suggestion to work, however, and didn't like having a separate .lua file in my WordPress directory. Thus I wrote my own rewrite rules.

My solution depends on WordPress' ability to do "fake" permalinks of the "/index.php/permalink" variety. I don't know when this was implemented, but it's in the most recent versions of WordPress.

Before going further, it's worth noting that I have Lighttpd set up to use mod_simple_vhost for virtual hosts:

1 simple-vhost.server-root   = "/path/to/www/"
2 simple-vhost.default-host  = "example.com"
3 simple-vhost.document-root = "/"

With the vhosts already specified (so simple!), the following code is all that is needed to get permalinks working:

1 $HTTP["host"] == "example.com" {
2 url.rewrite-once = (
3 "^/(.*\.php|wp-content/|wp-admin/|wp-includes/).*" => "$0",
4 "^/([^,]*)/?$" => "/index.php/$1";
5 )
6 }

Remember, of course, to turn on permalinks in WordPress under Settings -> Permalinks by choosing the "custom" setting and specifying what you want.

There may be various pieces of the site that this doesn't work for yet. If you find any, let me know and I'll update the rules. Essentially it catches requests for anything in the three main directories and passes those through while rewriting everything else behind index.php. Works like a charm!