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.
6 comments
if (not lighty.stat(lighty.env["physical.path"])) then
-- prefix (subfolder) without the trailing slash, e. g. "/blogs"
local prefix = ""
lighty.env["uri.path"] = prefix .. "/index.php"
lighty.env["physical.rel-path"] = lighty.env["uri.path"]
lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
end
Hmm.. Danke für die Erweiterung.Allerdings habe ich ein weiteres Problem hiermit festgestellt: PATH_INFO wird nicht korrekt behandelt, weil es in diesem Stadium noch in physical.path mit drin steckt. Das führt dazu, dass der stat-Test fehlschlägt und an index.php verwiesen wird, obwohl es an z.B. getfile.php gehen sollte.
Keine Lösung in Sicht, ausser dass darix und stbuehler im IRC das so auch für falsch halten.
Ja, das hast Du richtig verstanden.Die erste Reaktion war auch "physical.path sollte PATH_INFO nicht mehr enthalten".
Aber es stellte sich dann heraus, dass der "attract-physical-path-to"-Hook vor der PATH_INFO-Auflösung kommt.
