重定向后获取 404 文件 URL 的最佳方法是什么?

发布于 2024-08-20 01:36:52 字数 1298 浏览 13 评论 0原文

我正在使用一个需要将错误记录到数据库的 PHP 站点。因此,我设置了一个 .htaccess 文件,如下所示:

ErrorDocument 404 /404.php

404.php 包含将日志插入数据库所需的所有日志记录功能。我遇到的问题是检索触发 404 的文件的 URL。

以下是 $_SERVER 超全局数组的内容:

[HTTP_HOST] => {omitted}
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5
[HTTP_ACCEPT_ENCODING] => gzip,deflate
[HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
[HTTP_KEEP_ALIVE] => 300
[HTTP_CONNECTION] => keep-alive
[PATH] => /usr/local/bin:/usr/bin:/bin
[SERVER_SIGNATURE] => 
[SERVER_SOFTWARE] => Apache/2.2.8 (Ubuntu)
[SERVER_NAME] => {omitted}
[SERVER_ADDR] => {omitted}
[SERVER_PORT] => 80
[REMOTE_ADDR] => {omitted}
[DOCUMENT_ROOT] => {omitted}
[SERVER_ADMIN] => [no address given]
[SCRIPT_FILENAME] => /404.php
[REMOTE_PORT] => 19274
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] => 
[REQUEST_URI] => /404.php
[SCRIPT_NAME] => /404.php
[PHP_SELF] => /404.php
[REQUEST_TIME] => {omitted}

有什么建议吗?我读过的所有内容都推荐 HTTP_REFERER 项,但它似乎不存在。

提前致谢。

I'm working with a PHP site that needs to log errors to a database. As such, I've set up a .htaccess file as follows:

ErrorDocument 404 /404.php

404.php contains all of the logging functions necessary to insert the log into the database. What I'm having problems with is retrieving the URL of the file that triggered the 404.

Here are the contents of the $_SERVER superglobal array:

[HTTP_HOST] => {omitted}
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5
[HTTP_ACCEPT_ENCODING] => gzip,deflate
[HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
[HTTP_KEEP_ALIVE] => 300
[HTTP_CONNECTION] => keep-alive
[PATH] => /usr/local/bin:/usr/bin:/bin
[SERVER_SIGNATURE] => 
[SERVER_SOFTWARE] => Apache/2.2.8 (Ubuntu)
[SERVER_NAME] => {omitted}
[SERVER_ADDR] => {omitted}
[SERVER_PORT] => 80
[REMOTE_ADDR] => {omitted}
[DOCUMENT_ROOT] => {omitted}
[SERVER_ADMIN] => [no address given]
[SCRIPT_FILENAME] => /404.php
[REMOTE_PORT] => 19274
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] => 
[REQUEST_URI] => /404.php
[SCRIPT_NAME] => /404.php
[PHP_SELF] => /404.php
[REQUEST_TIME] => {omitted}

Any suggestions? Everything that I've read recommends the HTTP_REFERER item, but it doesn't seem to exist.

Thanks in advance.

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

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

发布评论

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

评论(1

不知所踪 2024-08-27 01:36:52

REQUEST_URI 旨在包含请求的 URL 路径和查询。

REQUEST_URI is meant to contain the requested URL path and query.

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