-- Helper Functions 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 -- Set for subdirectory drupal installs. Example: "/drupal" local prefix = '' -- If this is not an existing file if (not file_exists(lighty.env["physical.path"])) then -- Set local variables local FINAL_PATH = "empty" local request_uri = removePrefix(lighty.env["uri.path"], prefix) -- none should be set to '/' local query_string = lighty.env["uri.query"] local cookies = lighty.request["Cookie"] or "NOCOOKIE" -- filters for boost cache (anon+GET) to qualify boost caching local SERVE_CACHED_FLAG = (string.find(cookies, "DRUPAL_UID") == nil) and (lighty.env["request.method"] == "GET") local RESTRICTED_PATHS = (string.starts(request_uri, "/admin")) or (string.starts(request_uri, "/cache")) or (string.starts(request_uri, "/openid")) or (string.starts(request_uri, "/node/add")) or (string.starts(request_uri, "/user")) -- qualifies for boost cache type if (SERVE_CACHED_FLAG == true and RESTRICTED_PATHS == false) then -- Boost cache path (needs to be explicitly set here because it is not the same on my Lighty config as in .htaccess) -- (replace this with the path to your site's cache directory) local boost_cache_path = "/home/USER/public_html/SITE/cache" -- Build filename based on URL for the boost JS/CSS cache local perm_boost_path_uribase = boost_cache_path .. lighty.request["Host"] .. "/" .. request_uri .. "_" if (query_string) then normal_boost_path_uribase = normal_boost_path_uribase .. query_string end -- Set Final Path, Content-Type & Content-Encoding if this file exists. if (file_exists(perm_boost_path_uribase .. ".css")) then FINAL_PATH = perm_boost_path_uribase .. ".css" lighty.header["Content-Type"] = "text/css" elseif (file_exists(perm_boost_path_uribase .. ".js")) then FINAL_PATH = perm_boost_path_uribase .. ".js" lighty.header["Content-Type"] = "text/javascript" end -- do the actual redirection lighty.env["physical.path"] = FINAL_PATH end end