While moving a WordPress installation today to a new server I came across a weird situation involving permalinks. The new server was a Linux Ubuntu flavor running Lighttpd while the old one was a Windows 2008 running IIS. In order for friendly URLs and 404s to work properly, we had the following snippet added to the “lighttpd.conf” file (“mysite” is used as an example):

$HTTP["host"] =~ "(^|\.)mysite\.com$" {

	server.document-root = "/var/www/mysite.com/httpdocs"
	server.errorlog = "/var/www/mysite.com/error.log"
	accesslog.filename = "/var/www/mysite.com/access.log"
	server.error-handler-404 = "/index.php?error=404"

	var.wpdir = "/"

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

}

My custom permalink structure within WordPress was “/%postname%/”. After some testing I saw that everything was working fine, until I tried to edit a page in the admin section. That resulted in a page not found error. What was happening?

I thought I would then take a more careful look at the “lighttpd.conf” file just to verify that the rewrite module was installed and sure enough it was:

server.modules = (
	"mod_access",
	"mod_alias",
	"mod_compress",
	"mod_redirect",
	"mod_rewrite",
)

Do you see the issue? Hard to spot it is: the last item has a comma after it. Doubting if that was the issue, I removed the comma and restarted the Lighttpd service:

# /etc/init.d/lighttpd restart

Sure enough, things started working fine in the admin as well.

The crazy part is that if the comma was causing issues like it was apparently, why did it seem to work in the first place for the pubic site?

One Response to WordPress friendly URLs/404s with Lighttpd and things that can go wrong

  • A Friend

    Mate, you’ve saved my day and made me laugh at the same time.

    Can you please “rewrite” the word before the end? LOL!