Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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


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?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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