function file_exists(path) local attr = lighty.stat(path) if (attr and attr["is_file"]) 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 function string.starts(x,y) return string.sub(x,1,string.len(y)) == y end local prefix = '' if (not file_exists(lighty.env["physical.path"])) then -- if this is not an existing file lighty.header["Expires"] = "Sun, 19 Nov 1978 05:00:00 GMT" lighty.header["Cache-Control"] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0" local FINAL_PATH = "empty" local req_uri = lighty.env["request.uri"] local SERVE_CACHED_FLAG = (string.find((lighty.request["Cookie"] or "NOCOOKIE"), "DRUPAL_UID") == nil) and (lighty.env["uri.query"] == nil) and (lighty.env["request.method"] == "GET") -- 1st filter (anon+no_uriquery+GET) to qualify boost caching if (SERVE_CACHED_FLAG == true) then -- qualifies for boost cache type local boost_path_uribase = lighty.env["physical.doc-root"] .. "/cache/" .. lighty.request["Host"] .. "/0" .. req_uri if (req_uri == "/") then -- if path is front page local boost_path_frontpg = boost_path_uribase .. "index.html" -- path for boost cached file if (file_exists(boost_path_frontpg)) then FINAL_PATH = boost_path_frontpg -- serve boost cached path for front page end else local RESTRICTED_PATHS = (string.starts(req_uri,"/user")) or (string.starts(req_uri,"/cache")) or (string.starts(req_uri,"/admin")) -- 2nd filter to qualify boosted paths if (RESTRICTED_PATHS == false) then FINAL_PATH = ((file_exists(boost_path_uribase .. ".html") and (boost_path_uribase .. ".html")) or (file_exists(boost_path_uribase .. "/index.html") and (boost_path_uribase .. "/index.html")) or "empty") -- assign FINAL_PATH to file based on uribase being a file or base dir end end end if (FINAL_PATH == "empty") then -- file still missing. pass it to the fastcgi backend local request_uri = removePrefix(lighty.env["uri.path"], prefix) if request_uri then lighty.env["uri.path"] = prefix .. "/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"] FINAL_PATH = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"] end end lighty.env["physical.path"] = FINAL_PATH end