url.rewrite for WordPress on Lighttpd
15 Mar 2007This 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><br />
RewriteEngine On<br />
RewriteBase /<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteRule . /index.php [L]<br />
</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:
- a WordPress blog installed in the root of your (sub-) domain:
$HTTP["host"] =~ "{yourdomain}" {<br /> var.app = "{yourdomain}"<br /> accesslog.filename = base + "/logs/" + app + ".access.log"<br /> server.errorlog = base + "/logs/" + app + ".error.log"<br /> load php app<br /> url.rewrite = (<br /> "^/(wp-.+).*/?" => "$0",<br /> "^/(sitemap.xml)" => "$0",<br /> "^/(xmlrpc.php)" => "$0",<br /> "^/(.+)/?$" => "/index.php/$1"<br /> )<br /> }
- a WordPress blog installed in a subfolder (e.g. /blog/)
$HTTP["host"] =~ "{yourdomain}" {<br /> var.app = "{yourdomain}"<br /> accesslog.filename = base + "/logs/" + app + ".access.log"<br /> server.errorlog = base + "/logs/" + app + ".error.log"<br /> load php app<br /> url.rewrite = (<br /> "^/?$" => "/blog/index.php",<br /> "^/blog/(wp-.+)$" => "$0",<br /> "^/blog/xmlrpc.php" => "$0",<br /> "^/blog/sitemap.xml" => "$0",<br /> "^/blog/(.+)/?$" => "/blog/index.php/$1"<br /> )<br /> }
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:
<br />
$HTTP["host"] =~ "www.blog.forret.com" {<br />
url.redirect = ( ".*" => "")<br />
}<br />