自动重定向任何 http 错误代码

Redirect automatically any http error code

我实际上在我的 .htaccess 中使用了这个(例如):

ErrorDocument 404 /404.php

然后我为每个错误代码重复该行。 我想知道是否有办法自动重定向任何 http 错误代码并捕获此错误以动态重用它。

无法使用一个 ErrorDocument 指令来捕获所有错误。 http://httpd.apache.org/docs/current/mod/core.html#errordocument

另请参阅:http://httpd.apache.org/docs/current/custom-error.html

非 htaccess 解决方案可能是通过脚本路由 所有内容 并让脚本 return 获得相关的错误代码。但是,此 不会 处理某些错误,例如服务器抛出的 50* 个错误,这些错误会绕过脚本的 运行。

最好的解决方案仍然是为每个代码枚举 ErrorDocuments。