I've been working with lighttpd's mod_magnet recently to provide Routing & Controller logic to static web sites where PHP is a bit heavy handed (and Rails even more so.)
This Lua bit lets you happily leave those ugly file extensions off URL's:
- clean, simple URL's make the web human-friendly
- actual filename extensions (and application platform) can losslessly change over time
- script runs as a Lua bytecode machine in lighttpd core; it's fast
Save the following as extensionless_urls.lua next to your lighttpd.conf:
if (not lighty.stat(lighty.env["physical.path"])) then
file_extensions = { ".html", ".php" }
for key, file_extension in pairs(file_extensions) do
if (lighty.stat(lighty.env["physical.path"] .. file_extension)) then
lighty.env["uri.path"] = lighty.env["uri.path"] .. file_extension
lighty.env["physical.rel-path"] = lighty.env["uri.path"]
lighty.env["physical.path"] =
lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
break
end
end
end
Note the file_extensions array, which should be composed of the extensions to search for by priority. As shown above, an ".html" file will be found before a ".php" file by the same name. Keep this array short: one entry, if all your files have the same extension.
Adjust lighttpd.conf
# Include the mod_magnet early in the module list.
server.modules = ( "mod_magnet" )
# Call the Lua machine for each physical file request.
# Change this path to match the location of your script.
magnet.attract-physical-path-to = (
"/etc/lighttpd/extensionless_urls.lua" )
Restart lighttpd, and you now have stat-cached, fuzzy URL matching!
To get up-and-running with lighttpd+Lua, see:
mod_magnet on OS X
Thank you very much!