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]

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...

13 Responses to url.rewrite for WordPress on Lighttpd

  1. thanks man!

  2. Hey, was just curious, what version of Lighty are you running and have you had any other problems? I’ve tried a ton of rewrite rules and nothing seems to completely work with wordpress. I’m trying to migrate my blog to lighttpd 1.5 with WordPress 2.1 and running into a slew of problems, any javascript included in wordpress plugins with a version number attached returns a 404, some of my rewritten category links return an Octet stream instead of the page. I’m at a loss and about to give up on lighty. I tried your rules and my site doesn’t work at all, this is the closes I’ve come:

    url.rewrite-once = (
    “^/(wp-admin|images|wp-content|awstats)/{0,1}(?!no.css)(.*)” => “$0″,
    “^/.*\.(php|css|html|htm|pdf|png|gif|jpe?g|js)$” => “$0″,
    “^/.*?(\?.*)?$” => “/index.php$1″

  3. For those out there that are curious, this is what ended up working for me:

    url.rewrite-once = (
    “^/(wp-. ).*/?” => “$0″,
    “^/(sitemap.xml)” => “$0″,
    “^/(xmlrpc.php)” => “$0″,
    “^/keyword/([A-Za-z_0-9-] )/?$” => “/index.php?keyword=$1″,
    “^/.*?(?.*)?$” => “/index.php$1″


  4. Pingback: tin_the_fatty weblog » Blog Archive » WordPress Migrated to Run on Lighttpd+FastCGI/PHP5

  5. Pingback: Lighttpd dan ModRewrite | WordPress [at] mimpikami . com

  6. Pingback: Terbaik.Net » Blog Archive » Lighttpd dan ModRewrite

  7. Pingback: the real kucrut

  8. Pingback: Dennis 的無差別 Blog» Blog Archive - » Wordpress URL REWRITE on LIGHTTPD

  9. Pingback: Lighttpd ModRewrite pour Drupal, Wordpress, Dotclear et Zenphoto | bonvga.net

  10. This is the best known solution for Permalinks in WordPress+Lighttpd

    Please check: http://sudhaker.com/web-development/wordpress/wordpress-permalinks-lighttpd.html


  11. Pingback: wordpress, qTranslate & lighttpd | mriedel.org

  12. @Sudhaker: I beg to differ! I’ve seen about ten different approaches to this problem so far, but http://r00tshell.com/archives/2007/05/16/wordpress-lighttpd-permalinks-without-rewrite/ is the cleverest and simplest, and it looks like it solves other problems as well. Working great for me so far. Is there some important reason to introduce a dependency on Lua?

  13. I actually found this by experiment, but the easiest way to do this is to just set a server error string like

    server.error-handler-404 = “/index.php”

    this will support all permalink structures, and it returns a 200 code properly instead of 404…one line does it all!