404 Error Page in PHP

Is there any way to capture the information as to what page was not found when the not found page that is redirected to using the “ErrorDocument 404” statement in the .htaccess file can process PHP?

$_SERVER[“REQUEST_URI”] points to the “not found” page and I am trying to find out what page was requested that got redirected there.

Okay, I tried that and there’s no redirect header and all the page references that do exist are to the not found page.

Try this:



<?php /* missing.php to be saved in your root directory */

/*
	Apache config file: 'httpd.conf'
	requires activating:  ErrorDocument 404 /missing.php
*/

echo 'This file: ', __FILE__;
echo '<br />';

echo 'Original file request: ',
       (isset($_SERVER['REDIRECT_URL'])) 
       ?  $_SERVER['REDIRECT_URL'] 
       :  'NO REDIRECT_URL';

echo '<br />';

echo 'Original file request: ',
       (isset($_SERVER['REDIRECT_URI'])) 
       ?  $_SERVER['REDIRECT_URI'] 
       :  'NO REDIRECT_URI';

echo '<pre>';
	print_r($_SERVER);
echo '</pre>';


.

Thanks for the help.

Finally figured out that all the info about what was being requested was being blocked because the ErrorDocument statement in the .htaccess file was fully qualified including the domain name. I have now changed it to just specify the notfound filename after a slash and $_SERVER[“REQUEST_URI”] now contains the page that was requested that wasn’t found.

It worked fine for me but I did have to de-activate my personalised .htaccess file.

Did you:

  1. make the changes to your Apache http.conf file?
  2. after the changes stop and restart your LOCALHOST server?
  3. try the REQUEST_URI instead of REQUEST_URL server variable?
  4. check for an alernative server variable in the print_r($_SERVER) list?

If all the above checks are OK then I think you will need a .htacces expert.

.