Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 1.10 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. -- little helper function
  2. function file_exists(path)
  3.   local attr = lighty.stat(path)
  4.   if (attr) then
  5.       return true
  6.   else
  7.       return false
  8.   end
  9. end
  10. function removePrefix(str, prefix)
  11.   return str:sub(1,#prefix+1) == prefix.."/" and str:sub(#prefix+2)
  12. end
  13.  
  14. -- prefix without the trailing slash
  15. local prefix = '/hrlaws'
  16.  
  17. -- the magic ;)
  18. if (not file_exists(lighty.env["physical.path"])) then
  19.     -- file still missing. pass it to the fastcgi backend
  20.     request_uri = removePrefix(lighty.env["uri.path"], prefix)
  21.     if request_uri then
  22.       lighty.env["uri.path"] = "/index.php"
  23.       local uriquery = lighty.env["uri.query"] or ""
  24.       lighty.env["uri.query"] = uriquery .. (uriquery ~= "" and "&" or "") .. "q=" .. request_uri
  25.       lighty.env["physical.rel-path"] = lighty.env["uri.path"]
  26.       lighty.env["request.orig-uri"]  = lighty.env["request.uri"]
  27.       lighty.env["physical.path"]     = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
  28.     end
  29. end
  30. -- fallthrough will put it back into the lighty request loop
  31. -- that means we get the 304 handling for free. ;)