Schlagworte: lighttpd

12.10.08

Clean URLs with lighttpd

To get clean URLs (e.g. for permalinks) in Lighttpd, you have to use the magnet module (lighttpd-mod-magnet in Ubuntu/Debian), and a Lua script.

I've created a file /etc/lighttpd/rewrite-to-docroot.lua:

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

And enabled it using:

magnet.attract-physical-path-to = ("/etc/lighttpd/rewrite-to-docroot.lua")

This simulates the following mod_rewrite snippet known from Apache:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Previously I was using a tricky method, which would use the 404 handler ("server.error-handler-404 = /index.php"), but this caused missing GET params (as documented in the Lighttpd FAQ).
As a result, paged browsing of categories and tags wasn't possible.

Seitenleiste