Forum Moderators: coopster

Message Too Old, No Replies

404 header problem

404 header in php file not triggering error page

         

Addled

12:06 pm on May 11, 2006 (gmt 0)

10+ Year Member



Hi all,

Not sure whether this is a php problem or an apache problem.

I have a php script that generates a 404 header in some circumstances (then exits). However the custom error page doesnt appear. I just get a totally empty page.

'Proper' missing web pages do trigger my custom 404 page. The custom page is configured in an .htaccess file at the site root.

I've run the server header check [webmasterworld.com] on this site and get the following:
HTTP/1.1 404 Not Found
Date: Thu, 11 May 2006 11:54:08 GMT
Server: Apache/2.0.52 (Red Hat)
X-Powered-By: PHP/4.3.9
Set-Cookie: ELCWeb=5db284b7d0ebcfad3c63c1012d944bef; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 0
Connection: close
Content-Type: text/html; charset=ISO-8859-1

This seems to imply that the correct header is returned but apache is not responding properly. Any ideas?

whoisgregg

1:33 pm on May 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Once Apache has served the actual script page, it is not possible (as far as I know) to go backwards and tell Apache it actually should do it's standard 404 behavior.

However, it's easy to work around this:

header("HTTP/1.1 404 Not Found");
include($_SERVER['DOCUMENT_ROOT'].'/path/to/custom_404.php');
die;

(Although I actually put the header and the die in the custom_404.php page and just include it when appropriate.)

Addled

1:58 pm on May 11, 2006 (gmt 0)

10+ Year Member



Thanks for your reply. Your workaround works perfectly. I had misunderstood the interaction between php and apache (and hadn't thought of your method of getting the same effect)