30.11.2008lighttpd RewriteRule
Da ich meine Seite von Apache auf lighttpd umgestellt habe, bin ich auf ein Problem bei den RewriteRules gestoßen. Im Grunde ist das Problem ganz einfach und zwar kann das Rewrite Modul von lighttpd nicht prüfen ob eine Datei existiert. Durch einen Tipp von Daniel ist mir ein kleines Lua Script gelungen womit ich Prüfen kann ob eine Datei existiert.
RewriteRules unter Apache:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php?p=$1 [L]
Damit es auch unter lighttpd richtig funktioniert, muss zunächst das Modul lighttpd-mod-magnet installiert und aktiviert werden.
Installieren unter Ubuntu:
Lua Script speichern nach /etc/lighttpd/rewrite.lua
local result = { }
local from = 1
local delim_from, delim_to = string.find( self, delimiter, from )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from )
end
table.insert( result, string.sub( self, from ) )
return result
end
if ( not lighty.stat( lighty.env['physical.path'] ) ) then
local index_file = "/index.php"
local last_found = ""
local path = ""
for key,col in ipairs( ( lighty.env['physical.path']:sub( 2 )):split( "/" ) ) do
path = path .. "/" .. col
if( lighty.stat( path ) ) then
last_found = path
end
end
if( last_found == lighty.env["physical.doc-root"] ) then
lighty.env["uri.path"] = index_file
end
lighty.env["physical.rel-path"] = lighty.env["uri.path"]
lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
end
Nun muss das Script nur noch in dem V-Host eingebunden werden:
...
magnet.attract-physical-path-to = ( '/etc/lighttpd/rewrite.lua' )
...
}