Lighttpd – 404错误时重写请求

我有问题,如果有可能在发生404错误时运行mod_rewrite规则。 例:

要求: http : //domain.com/files/img/file.jpg

如果没有/files/file.jpg ,那么Lightttpd应该重写请求到文件/files2/img/file.jpg

如何在lighttpd / mod_rewriteconfiguration文件中做到这一点?

你应该使用mod_magnet并编写简单的lua脚本来完成这项工作。

# 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" end end 

以上链接中的更多示例。