简体   繁体   中英

Error pages in .htaccess - find the requested page?

I use my .htaccess file to redirect visitors with errors to my custom error pages.
The server is an Apache with PHP 5.2 so I code in PHP.
I wish to know, on my PHP error pages, what page did the visitor request and gave an error?

$_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'] .

In order to test it, I would advise to make a script, say info.php, which has:

 <?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.

Of course, do not do it on publicly accessible server since phpinfo() has a lot of sensitive information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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