Jim's Stream

Drupal fixed up a little more

I fixed up the lua script that provides "clean" urls for drupal on lighty.

Heres the relevant lighttpd.conf section

$HTTP["host"] == "jlporter.com"{ server.document-root = var.basedir+"/blah/"
index-file.names = ( "index.php" )
magnet.attract-physical-path-to = ( "/etc/lighttpd/rewrite_drupal2.lua" )
}

rewrite_drupal2.lua originally obtained from: http://pixel.global-banlist.de/drupal.lua and linked from the lighty wiki: http://redmine.lighttpd.net/wiki/lighttpd
section 3 #26

I only modified the prefix variable because I don't use sitename/drupal for my drupal install (it's / on my site).

-- little helper function
function file_exists(path)
local attr = lighty.stat(path)
if (attr) then
return true
else
return false
end
end
function removePrefix(str, prefix)
return str:sub(1,#prefix+1) == prefix.."/" and str:sub(#prefix+2)
end

-- prefix without the trailing slash
local prefix = ''
-- was /drupal
-- the magic ;)
if (not file_exists(lighty.env["physical.path"])) then
-- file still missing. pass it to the fastcgi backend
request_uri = removePrefix(lighty.env["uri.path"], prefix)
if request_uri then
lighty.env["uri.path"] = "/index.php"
local uriquery = lighty.env["uri.query"] or ""
lighty.env["uri.query"] = uriquery .. (uriquery ~= "" and "&" or "") .. "q=" .. request_uri
lighty.env["physical.rel-path"] = lighty.env["uri.path"]
lighty.env["request.orig-uri"] = lighty.env["request.uri"]
lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
end
end
-- fallthrough will put it back into the lighty request loop
-- that means we get the 304 handling for free. ;)