Php – 404 custom error page redirect doesn’t show missing file URL

custom-error-pageshttp-status-code-404PHPredirecturl

I have a custom 404 error page on my site, but while doing other things on the site, the error page makes it hard to figure out what my missing file problems are because it redirects to a given html or php file and takes the URL of the missing file out of the address bar and replaces it with the URL of the custom error page.

So for example, when users log in to the site, I have it link to a php file when they hit submit, but then the browsers takes them straight to the 404 error page, so I can't see that the problem is actually a link to one directory higher than it should be.

I've tried printing the URL of the missing file to the page using php, but the server just grabs the URL of the 404 error page, rather than the original missing file URL. Here is how I tried doing that: http://members.cox.net/midian/tutorials/php404.htm

How can I either show the custom error page while keeping the original missing URL in the address bar, or print out the URL of the missing file to the page?

Best Answer

If your error pages are redirected to a PHP powered 404 page then the variable $_SERVER["HTTP_REFERER"] should contain something interesting. Having said that, redirecting to a error-404 page is a bad practice. It confuses search engines and human visitors alike.

Edit

Here is a solution that works on Apache. Add this line to your .htaccess file:

ErrorDocument 404 /error-404.php

Create a file called error-404.php in the root directory of your website with the following content:

<?php
echo "<h1>404 Not Found</h1>";
echo "<p>The page {$_SERVER['REQUEST_URI']} was not found on this server</p>";

screenshot of the error page with firebug