Apache:返回 404 错误而不是 500 错误
在 apache 中,每当收到 500 错误时,我想返回 404 错误。
我知道这是一个非常奇怪的用例,但我想知道它是否可能。
我发现这个
http://www.4webhelp.net/tutorials/misc/errors.php
这让我相信你可以改变不同错误发生的情况。 像这样的东西会很棒
ErrorDocument 404 /cgi-bin/error404.cgi
ErrorDocument 500 /cgi-bin/error404.cgi
正如文章所建议的,但我的 Ubuntu 安装上似乎没有 error404.cgi 。 知道在哪里可以得到它,或者有替代解决方案吗?
In apache I'd like to return 404 errors whenever I get a 500 error.
Its a very strange use case, I know, but I'm wondering if its possible.
I found this
http://www.4webhelp.net/tutorials/misc/errors.php
Which leads me to believe you can change what happens on the different errors. Something like this would be great
ErrorDocument 404 /cgi-bin/error404.cgi
ErrorDocument 500 /cgi-bin/error404.cgi
As suggested by the article, but I don't seem to have error404.cgi on my Ubuntu installation. Any idea where I can get it, or an alternative solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这不能回答您的问题,但您确定您真的想这样做吗? 500 错误和 404 是非常不同的东西,意味着用于不同的目的。 您告诉用户他们拥有的网址是错误的,而实际上这很可能是您的应用程序/服务器的临时问题。 为什么您宁愿这样做,而不是告诉用户存在暂时的问题,他们应该稍后再试? 或者换句话说,为什么不直接定制一个 500 错误页面呢?
I know this doesn't answer your question but are you sure that you really want to do this? a 500 error and 404 are very different things meant to be used for different purposes. You are telling a user that the url that they have is wrong when in fact it is what is more than likely a temporary problem with your application/server. Why would you rather do this than to tell the user there is a temporary problem and they should try again later on? Or in other words, why not just have a custom 500 error page?
您必须创建 error404.cgi。 转到 /usr/lib/cgi-bin,然后创建一个名为 error404.cgi 的文件,它应该是 Perl(默认),或者如果启用了 Python,则可以使用其中之一。 如果您不懂 Python 或 Perl,这里有一个应该适合您的基本 Perl 脚本:(您可以从我的网站 cwarren.uuuq.com/downloads/perl/404.pl 下载该脚本
另一种选择是更改/var/www/404.html 或其他内容的链接。
You have to create error404.cgi. Go to /usr/lib/cgi-bin and then create a file called error404.cgi it should be either Perl (default) or if Python is enabled, you can use either. If you do not know either Python or Perl, heres a basic Perl script which should work for you: (You can download the script from my website at cwarren.uuuq.com/downloads/perl/404.pl
Another option would be to change the link to /var/www/404.html or something.