wordpress

Database

When changing the domain for a WordPress installation, update home and siteurl fields in wp_options table to the new domain.

Lighttpd

WordPress runs perfectly fine on Lighttpd, but when it comes to having pretty permalinks things start to get a little bit tricky. Running on Apache, WordPress uses a few mod_rewrite rules for pretty permalinks. WordPress either automatically writes these rules to an .htaccess file, or if it does not have the required permissions to do so, displays them for the user to add to .htaccess manually. This what an .htaccess file generated by WordPress MU looks like (it might or might not be different from an .htaccess file written by regular WordPress):

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

What it does, in a nutshell, is it checks whether a requested URL refers to an actual file or a directory on disk. If it does, the file or directory contents is returned by Apache; if it doesn't, WordPress' index.php is displayed. mod_rewrite's magic ends here and WordPress figures out which page to display by examining $_SERVER['REQUEST_URI'] that contains the original, pre-mod_rewrite-fiddled URL. Since there is no clone of mod_rewrite for Lighttpd, a workaround is required to make things work. I've come across two such workarounds.

Workarounds

The following instructions assume that you virtual host config used for running WordPress looks like so:

$HTTP["host"] =~ "^(www\.)?example\.org$" {
    server.document-root = "/var/www/wordpress/"
    accesslog.filename = "/var/log/wordpress_access.log"
}

I prefer to put virtual host configurations in /etc/lighttpd/lighttpd.conf, Lighttpd's main config file, but you might put them in one of lighttpd.conf's includes.

Workaround 1

Based on a workaround found on Guy Rutenberg's blog, this workaround does not actually correspond to the rules in .htaccess above. Instead, it assumes that no dots are used in WordPress' permalinks (URLs). If there is a dot in the URL, it must be an actual file on disk that should be displayed. With a rule to avoid redirection of /wp-admin (URL to the admin panel) lighttpd.conf should look like this:

$HTTP["host"] =~ "^(www\.)?example\.org$" {
    server.document-root = "/var/www/wordpress/"
    accesslog.filename = "/var/log/wordpress_access.log"

    url.rewrite = (
        "^/(.*)\.(.+)$" => "$0",
        "^/wp-admin/?$" => "$0",
        "^/(.+)/?$" => "/index.php"
    )
}

Workaround 2

This one uses a mod_magnet and a LUA script to achieve the same effect as WordPress' .htaccess file. Robust, but some complain that LUA slows Lighttd down. Save the following code in /etc/lighttpd/rewrite_to_docroot.lua:

-- Script used with lighttpd's mod_magnet to get pretty permalinks in WordPress
--
-- http://daniel.hahler.de/clean-urls-with-lighttpd

if (not lighty.stat(lighty.env["physical.path"])) then
    lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. "index.php"
end

Change your lighttpd.conf to:

$HTTP["host"] =~ "^(www\.)?example\.org$" {
    server.document-root = "/var/www/wordpress/"
    accesslog.filename = "/var/log/wordpress_access.log"

    magnet.attract-physical-path-to = ("/etc/lighttpd/rewrite_to_docroot.lua")
}