如何检测哪个页面导致内部服务器错误?

发布于 2024-09-09 07:09:29 字数 351 浏览 6 评论 0原文

因此,在我的 .htaccess 文件中,我有以下 ErrorDocument 行:

ErrorDocument 500 http://www.example.com/500

由于我的服务器从相同的核心文件运行多个网站,我只想将所有内部服务器错误重定向到同一处理页面。但是,我的问题是它不会发送有关导致错误的页面的任何信息,它会重定向页面。我尝试将其更改为 ErrorDocument 500 index.php?500 但这只会在尝试查找文件时导致第二个内部服务器错误。关于如何成功地将其重定向到自定义 500 错误页面并仍然获取有关最初导致错误的页面的信息,有什么想法吗?

So, in my .htaccess file I have this ErrorDocument lines:

ErrorDocument 500 http://www.example.com/500

Since my server runs multiple websites from the same core files, I just want to redirect all internal server errors to the same processing page. However, my problem is that it doesn't send any information about the page that cause the error, it redirects the page. I tried changing it to ErrorDocument 500 index.php?500 but that just causes a second internal server error when trying to locate the file. Any ideas on how I can successfully redirect it to my custom 500 error page and still acquire information about the page that caused the error in the first place?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

樱&纷飞 2024-09-16 07:09:29

ErrorDocument 语句中,您提供了远程页面的 URL。结果,Apache 向用户发送了一个 Location 标头,然后用户就愉快地离开了。

相反,请将 URL 更改为将处理错误的本地脚本的绝对路径:

ErrorDocument 500 /500.php

应使用一组以 REDIRECT_ 开头的环境变量启动脚本,该变量应包含错误中涉及的各种路径和查询字符串。

无法既将用户发送到其他地方,又捕获 ErrorDocument 本身内的信息。另一方面,如果您出于某种原因仍想以这种方式处理信息,您的脚本可以捕获信息,然后重定向用户。

In your ErrorDocument statement, you're giving a URL to a remote page. As a result, Apache sends the user a Location header, and the user goes off on their merry way.

Instead, change the URL to an absolute path to a local script that will handle the error:

ErrorDocument 500 /500.php

The script should be launched with a set of environment variables starting with REDIRECT_ that should contain the various paths and query strings involved in the error.

There is no way to both send the user elsewhere and also capture the information within ErrorDocument itself. On the other hand, your script can capture the information and then redirect the user, if you still want to handle it that way for some reason.

如果没有 2024-09-16 07:09:29

您始终可以查看 http 请求的 referrer 字段来确定调用者之前访问过哪个 URL

You could always look in the referrer field of the http request to determine on which URL the caller was before

独闯女儿国 2024-09-16 07:09:29

检查您的网络服务器的访问日志。在那里您将能够看到哪个请求导致了 500 响应代码。

在 Apache(使用默认日志格式)中,成功的请求 (200 OK) 可能如下所示:

127.0.0.1 - - [19/Jul/2010:18:25:54 +0200] "GET / HTTP/1.1" 200 663 "-" "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8pre) Gecko/20100718 Ubuntu/10.04 (lucid) Namoroka/3.6.8pre"

导致 500 的请求可能如下所示:

127.0.0.1 - - [19/Jul/2010:18:24:37 +0200] "GET / HTTP/1.1" 500 631 "-" "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8pre) Gecko/20100718 Ubuntu/10.04 (lucid) Namoroka/3.6.8pre"

响应代码位于第六列中。

您还可以检查 PHP 错误日志,假设您已启用错误日志记录(您应该这样做),其中将包含所有 PHP 错误。

Check your webserver's access log. There you will be able to see which request that is causing the 500 response code.

In Apache (using the default log format), a successful request (200 OK) could look like this:

127.0.0.1 - - [19/Jul/2010:18:25:54 +0200] "GET / HTTP/1.1" 200 663 "-" "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8pre) Gecko/20100718 Ubuntu/10.04 (lucid) Namoroka/3.6.8pre"

A request that results in a 500 could look like this:

127.0.0.1 - - [19/Jul/2010:18:24:37 +0200] "GET / HTTP/1.1" 500 631 "-" "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8pre) Gecko/20100718 Ubuntu/10.04 (lucid) Namoroka/3.6.8pre"

The response code is in the sixth column.

You can also check your PHP error log, which will contain all PHP errors assuming you've enabled error logging (you should).

为你鎻心 2024-09-16 07:09:29

您的 apache 服务器会记录发生的每个错误(尽管它是可配置的)。您可以在 PHP 中使用 FileStream 打开和管理此文件网站。请参阅http://httpd.apache.org/docs/2.2/logs.html 查看有关 Apache 日志文件的更多信息。您可以从 http://www.freewebmasterhelp.com/tutorials/htaccess/ 获取有关 .htaccess 的教程

要进行您自己的处理,请创建一个 PHP 文件(例如 error.php),它将处理您的错误。您可以使用 .htaccess 文件重定向它。之后,如果您想转到某个页面,可以使用 header() 方法。

Your apache server logs every Error occurs(Though it is configurable). You can able to open and manage this file using FileStream in your PHP website. See http://httpd.apache.org/docs/2.2/logs.html to see more about Apache log file. You can get a tutorial on .htaccess from http://www.freewebmasterhelp.com/tutorials/htaccess/.

To make your own processing, make a PHP file like error.php which will process your errors. You can redirect it using .htaccess file. After that if you want to go to a page you can do that by using header() method.

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