简体   繁体   English

.htaccess中的错误页面-查找请求的页面?

[英]Error pages in .htaccess - find the requested page?

I use my .htaccess file to redirect visitors with errors to my custom error pages. 我使用.htaccess文件将有错误的访问者重定向到我的自定义错误页面。
The server is an Apache with PHP 5.2 so I code in PHP. 该服务器是具有PHP 5.2的Apache,因此我使用PHP编写代码。
I wish to know, on my PHP error pages, what page did the visitor request and gave an error? 我想知道,在我的PHP错误页面上,访客请求了哪个页面并给出了错误?

$_SERVER['REQUEST_URI']

or 要么

$_SERVER['REDIRECT_URL'] 

should give you the information. 应该给你的信息。

If you are doing it via ErrorDocument, you should find the original URL in $_SERVER['REQUEST_URI'] and in $_SERVER['REDIRECT_URL'] . 如果通过ErrorDocument进行操作,则应在$_SERVER['REQUEST_URI']$_SERVER['REDIRECT_URL']找到原始URL。

In order to test it, I would advise to make a script, say info.php, which has: 为了对其进行测试,我建议创建一个脚本,例如info.php,该脚本具有:

 <?php
 phpinfo();

and then do something like: 然后执行以下操作:

 ErrorDocument 404 /somepath/info.php

And then when you call to non-existing document, you'll receive phpinfo() output that lists all variables you have and you can see which ones fit your purposes. 然后,当您调用不存在的文档时,您将收到phpinfo()输出,其中列出了您拥有的所有变量,并且您可以看到哪些变量符合您的目的。

Of course, do not do it on publicly accessible server since phpinfo() has a lot of sensitive information. 当然,不要在可公开访问的服务器上执行此操作,因为phpinfo()具有很多敏感信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM