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

15 thoughts on “url.rewrite for WordPress on Lighttpd”

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

  2. Pingback: the real kucrut
  3. 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!

  4. I am using this code creating a custom url . I am having some issues in the code as it’s not functioning properly. I have implemented this code reading the tutorial https://www.wpblog.com/wordpress-url-rewrite-for-custom-page-template/

    function prefix_news_rewrite_rule() {
    add_rewrite_rule( ‘news/([^/]+)/photos’, ‘index.php?news=$matches[1]&photos=yes’, ‘top’ );
    add_rewrite_rule( ‘movie/([^/]+)/videos’, ‘index.php?news=$matches[1]&videos=yes’, ‘top’ );

    add_action( ‘init’, ‘prefix_news_rewrite_rule’ );

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.