Lighttpd is a wonderful webserver if you don’t need all the power that lurks within the enigma that is Apache. (And don’t even mention IIS to me, I don’t want to hear about it.) But when setting up WordPress on Lighttpd it can take a little tweaking to get the permalink URLs right. And, of course, we want to use permalinks so that our URLs don’t look like a string of swear words with &s, ?s, and /s.
My first resource was the WordPress Codex, which pointed me to this post. I couldn’t get his suggestion to work, however, and didn’t like having a separate .lua file in my WordPress directory. Thus I wrote my own rewrite rules.
My solution depends on WordPress’ ability to do “fake” permalinks of the “/index.php/permalink” variety. I don’t know when this was implemented, but it’s in the most recent versions of WordPress.
Before going further, it’s worth noting that I have Lighttpd set up to use mod_simple_vhost for virtual hosts:
simple-vhost.server-root = “/path/to/www/”
simple-vhost.default-host = “smidg.in”
simple-vhost.document-root = “/”
With the vhosts already specified (so simple!), the following code is all that is needed to get permalinks working:
$HTTP["host"] == “smidg.in” {
url.rewrite-once = (
“^/(.*\.php|wp-content/|wp-admin/|wp-includes/).*” => “$0″,
“^/([^,]*)/?$” => “/index.php/$1″
)
}
Remember, of course, to turn on permalinks in WordPress under Settings -> Permalinks by choosing the “custom” setting and specifying what you want.
There may be various pieces of the site that this doesn’t work for yet. If you find any, let me know and I’ll update the rules. Essentially it catches requests for anything in the three main directories and passes those through while rewriting everything else behind index.php. Works like a charm!
Tags: lighttpd, mod_rewrite, permalinks, wordpress
Just because you were wanting to know, IIS doesn’t have rewriting abilities built in. You have to use a seperate plugin.
This seems to do the trick too:
server.error-handler-404 = “/index.php?error=404″
Apparently, if LightTPD tells WordPress to display a 404 page, WordPress checks the permalink scheme to see if the requested URL points to a working page and shows it if it does. So you’re in effect moving all of the permalinking logic into WordPress instead of dividing it to an external rewrite module.
This is the best known solution for Permalinks in WordPress+Lighttpd
Please check: http://sudhaker.com/web-development/wordpress/wordpress-permalinks-lighttpd.html
Cheers,
Sudhaker
I really fail to see how that solution is any better than the one I propose. Both are very simple, and seem to preserve full WordPress functionality, as well as handling 404 pages correctly. Both require enabling an extra module (mod_rewrite or mod_magnet).
On the one hand, my solution does not require the extra “rewrite.lua” to be placed in the site’s home directory, thus eliminating one more file to keep track of. On the other hand, the solution you propose doesn’t have to specify the overrides manually for each of the three main WordPress directories manually.
I don’t think you can claim that either is the “best known solution.” Both are known and valid solutions that seem to do the trick.