File path in 404

hankknight
hankknight used Ask the Experts™
on
I want 404 errors to display the path in which Apache looked for a file.  

For example, if a user goes here:
http://www.example.com/images/bad.gif

The 404 error should display this:

"Unable to find file at /home/examplecom/www/images/bad.gif"

Is that possible?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Consultant & Challenge Subduer
Top Expert 2009
Commented:
Are you sure you want to show the server file path and not the web path?

Anyway, like the page that aiklamba linked to says, you can create a custom error page by using the "ErrorDocument" directive, for example:
ErrorDocument 404 /404.php

Open in new window

You can then use a little PHP code to print out either path (assuming there's no redirect in place). You can try these three different lines to see which one you want to use:
<?php echo $_SERVER['SCRIPT_FILENAME']; ?>
<?php echo $_SERVER['SCRIPT_NAME']; ?>
<?php echo $_SERVER['REQUEST_URI']; ?>

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial