I have question if it is possible do run mod_rewrite rule when 404 error occurs. Example:

Request: http://domain.com/files/img/file.jpg

If there is no /files/file.jpg, then Lightttpd should rewrite request to file /files2/img/file.jpg

How to do that in lighttpd/mod_rewrite conf?


You should use mod_magnet and write simple lua script to do this job.

# lua redirect example
# match URI for /files
if (string.match(lighty.env["uri.path"], "^/files")) then
  # test file existence with stat()
  if (not lighty.stat(lighty.env["physical.path"])) then
    lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. "/files2/img/file.jpg"

More examples in link above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.