如何记录“未找到”哪个页面? (尝试使用 htaccess、php、http_referer 自定义错误页面)
我只是想知道如何获得 在我的网站上找不到该网页的链接。
使用以下 .htaccess 代码,当请求不存在的页面时,用户将被重定向到 my_404.php。
Options -Indexes
ErrorDocument 404 http://mysite.com/my_404.php
如果我必须追踪未找到的页面链接是什么,我该怎么做?
例如,A.php 是一个有效的网页,而 b.php 则不是。 因此,如果我在 A.php 上并尝试查看 b.php (不存在的页面).. .htaccess 将我重定向到 my_404.php,我在其中看到 HTTP_REFERER
为 A.php .. 但是我正在寻找的是“有人试图查看 B.php”。 我怎么做?
感谢您的帮助。
编辑
请参阅:我不想签入日志文件。 我正在询问页面上的一些内容。 谢谢。
I was just wondering how to get
the link of the webpage which was not found on my website.
With following .htaccess code, when a non-existing page is requested, user is redirected to my_404.php.
Options -Indexes
ErrorDocument 404 http://mysite.com/my_404.php
If I have to track down what was the link of the page, which was not found, how do I do that??
Just for example, A.php is a valid web page, while b.php is not. So if I am on A.php and try to view b.php (non-existent page) .. .htaccess redirects me to my_404.php on which I see HTTP_REFERER
as A.php .. but what I am looking for is that "somebody tried to view B.php". How do I do that?
Thanks for your help.
EDIT
Please see: I dont want to check in log files. I am asking about something on page. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当您使用像
http://mysite.com/my_404.php
这样的远程 ErrorDocument URL 时,Apache 会将指向该 URL 的重定向发送给客户端,这就是为什么您无法获取导致的 URL就像 Matt Bridges 建议的那样,来自$_SERVER['REQUEST_URI']
的 404。您可能想尝试使用本地 ErrorDocument(没有方案和服务器名称),如下所示:
我怀疑
$_SERVER['REQUEST_URI']
将返回最初请求的 URL。When you use a remote ErrorDocument URL like
http://mysite.com/my_404.php
, Apache will send a redirect to that URL to the client, that's why you can't get the URL that causes the 404 from$_SERVER['REQUEST_URI']
like Matt Bridges suggested.You might want to try using a local ErrorDocument (no scheme and servername), like this:
I suspect
$_SERVER['REQUEST_URI']
will then return the originally requested URL.这可能已经在您的 Apache 日志文件中完成。 您可以只解析数据而不是记录两次。
Stackoverflow Archives:
其他相关内容:
This is likely already being done in your Apache log file. You could just parse the data rather than recording it twice.
Stackoverflow Archives:
Additional Relevant Content:
您正在查找的变量称为 $_SERVER['REQUEST_URI']。 它保存客户端向服务器发出的原始请求。
您可以在此处查看其他“$_SERVER”变量的列表。
编辑:
经过一番谷歌搜索后,您的问题是您的错误页面是用 http:// 限定符指定的。 更改您的 htaccess,以便将 ErrorDocument 指定为本地文件,例如:
执行此操作后, $_SERVER['REQUEST_URI'] 应保存正确的值。
The variable you are looking for is called $_SERVER['REQUEST_URI']. It holds the original request that was made to your server by the client.
You can see a list of the other "$_SERVER" variables here.
Edit:
After a bit of google searching, your problem is that your error page is specified with the http:// qualifier. Change your htaccess so that the ErrorDocument is specified as a local file, e.g.:
After you do that, $_SERVER['REQUEST_URI'] should hold the correct value.
看看
my_404.php
中的$_SERVER
数组,我想您会找到您需要的内容。 :-)
Have a look at your
$_SERVER
array inmy_404.php
I guess you'll find what you need. :-)