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")
}

Related posts:

  1. WP-Cache speeds up your WordPress! Ever wondered if you needed a caching plugin for your...
  2. Migration to WordPress: me vs Murphy Some of you might have noticed my recent domain dance:...
  3. Migrating from Blogger to WordPress 2.0 Ever since I saw the new ‘import from Blogger’ functionality...
  4. Fancy WordPress themes on Dreamhost It used to be that when you installed WordPress on...
  5. Create your own WordPress plugin Wordpress has a really nifty system for adding functionality: the...

6 Responses to “url.rewrite for WordPress on Lighttpd”


Comments are currently closed.