Apache:返回 404 错误而不是 500 错误

发布于 2024-07-25 08:45:18 字数 459 浏览 3 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

無處可尋 2024-08-01 08:45:18

我知道这不能回答您的问题,但您确定您真的想这样做吗? 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?

五里雾 2024-08-01 08:45:18

您必须创建 error404.cgi。 转到 /usr/lib/cgi-bin,然后创建一个名为 error404.cgi 的文件,它应该是 Perl(默认),或者如果启用了 Python,则可以使用其中之一。 如果您不懂 Python 或 Perl,这里有一个应该适合您的基本 Perl 脚本:(您可以从我的网站 cwarren.uuuq.com/downloads/perl/404.pl 下载该脚本

#!/usr/bin/perl
use strict;
print "<html>";
print "<head>";
print "<title>404 ERROR!</title>";
print "</head>";
print "<body>";
print "<h1>Sorry for the broken link, but this page is not here!</h1>";
print "<br><br>";
print "<a href=\"javascript:history.go(-1)\">Click here to go back to the previous page.</a>";
exit(0);

另一种选择是更改/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

#!/usr/bin/perl
use strict;
print "<html>";
print "<head>";
print "<title>404 ERROR!</title>";
print "</head>";
print "<body>";
print "<h1>Sorry for the broken link, but this page is not here!</h1>";
print "<br><br>";
print "<a href=\"javascript:history.go(-1)\">Click here to go back to the previous page.</a>";
exit(0);

Another option would be to change the link to /var/www/404.html or something.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文