url.rewrite for Wordpress on Lighttpd

LightyThis blog now runs on a Lighttpd (Lighty) webserver instead of Apache, and this means the configuration for ‘pretty URLs’ or permalinks of Wordpress doesn’t work like it used to.
(As you might have noticed, I use permalinks like /2007/02/this-is-permalink/)

Whereas Wordpress can automatically adapt the Apache .htacccess file to something like
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

it does not do anything automatically for your Lighty .conf configuration file (which is logical, since an application should not be allowed to mess with a central config file).

So what you have to use is:

  1. a Wordpress blog installed in the root of your (sub-) domain:
    $HTTP["host"] =~ "{yourdomain}" {
    var.app = "{yourdomain}"
    accesslog.filename = base + "/logs/" + app + ".access.log"
    server.errorlog = base + "/logs/" + app + ".error.log"
    load php app
    url.rewrite = (
    "^/(wp-.+).*/?" => "$0",
    "^/(sitemap.xml)" => "$0",
    "^/(xmlrpc.php)" => "$0",
    "^/(.+)/?$" => "/index.php/$1"
    )
    }
  2. a Wordpress blog installed in a subfolder (e.g. /blog/)
    $HTTP["host"] =~ "{yourdomain}" {
    var.app = "{yourdomain}"
    accesslog.filename = base + "/logs/" + app + ".access.log"
    server.errorlog = base + "/logs/" + app + ".error.log"
    load php app
    url.rewrite = (
    "^/?$" => "/blog/index.php",
    "^/blog/(wp-.+)$" => "$0",
    "^/blog/xmlrpc.php" => "$0",
    "^/blog/sitemap.xml" => "$0",
    "^/blog/(.+)/?$" => "/blog/index.php/$1"
    )
    }

The xmlrpc.php rule is necessary for external access (like, publishing from del.icio.us or Flickr), and the sitemap.xml file is something for Google Sitemaps.

For those stubborn visitors who always precede their URLs with www, you can also add a redirect:

$HTTP["host"] =~ "www.blog.forret.com" {
url.redirect = ( ".*" => "http://blog.forret.com")
}

  • del.icio.us
  • digg
  • Reddit
  • Facebook
  • FriendFeed

If you're new here, you may want to subscribe to my RSS feed or receive updates via email. Thanks for visiting!

Related posts:

  1. My 10 essential Wordpress plugins Since I’ve been doing quite a lot of Wordpress...
  2. Migration to Wordpress: me vs Murphy Some of you might have noticed my recent domain dance:...
  3. WP-Cache speeds up your Wordpress! Ever wondered if you needed a caching plugin for your...
  4. Migrating from Blogger to Wordpress 2.0 Ever since I saw the new ‘import from Blogger’ functionality...
  5. Create your own Wordpress plugin Wordpress has a really nifty system for adding functionality:...

5 Responses to “url.rewrite for Wordpress on Lighttpd”


Leave a Reply