Vercas
Vercas

Reputation: 9141

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?

Upvotes: 2

Views: 215

Answers (2)

StasM
StasM

Reputation: 11022

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.

Upvotes: 2

Dr.Molle
Dr.Molle

Reputation: 117334

$_SERVER['REQUEST_URI']

or

$_SERVER['REDIRECT_URL'] 

should give you the information.

Upvotes: 2

Related Questions