Welcome to WebmasterWorld Guest from 54.145.208.64

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

header "404 Not Found"

   
2:14 pm on Jan 29, 2008 (gmt 0)

5+ Year Member



The .htaccess I have set up converts any 'directory_name' to index.php?ref=directory_name

The content management system then tries to extract this page from the database and if it doesn't exist, sets a page header as follows

header("HTTP/1.0 404 Not Found");

The only problem is that instead of the user seeing the 404.shtml which is on the server, they just see a blank page. The status code returned is correct though.

I've tried adding a second line as follows
header("Location: /404.shtml");

But this ofcourse results in a 302 as the file 404.shtml can be found.

So I'm wondering how could I have my users referred to the correct 404.shtml and receive the correct 404 status.

any suggestions?

2:28 pm on Jan 29, 2008 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Instead of redirecting the user to the custom 404 page, just include it with your 404 header:

header("HTTP/1.0 404 Not Found");
include($_SERVER['DOCUMENT_ROOT'].'/404.shtml');
die;
2:31 pm on Jan 29, 2008 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



have you specified your custom 404 document in the configuration?

ErrorDocument 404 /404.shtml
2:36 pm on Jan 29, 2008 (gmt 0)

10+ Year Member



Somewhere I read, and it makes sense, that the 404 page isn't included in that situation because to Apache it's not really a 404. The header is sent correctly to the browser, but since it's done at the PHP level and not the web server level Apache doesn't know about it so it doesn't send the 404 page. What I do is similar to an earlier thread and send the header, include my error page, and die()
3:32 pm on Jan 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, what nutter said makes sense from your description:

The content management system then tries to extract this page from the database and if it doesn't exist, sets a page header as follows

In this case, Apache isn't doing the work for you, the CMS is.

3:41 pm on Jan 29, 2008 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



i think what you say is true only for non-parsed header scripts.
it is quite common for apache to change and/or add headers to the response.
4:06 pm on Jan 29, 2008 (gmt 0)

5+ Year Member



header("HTTP/1.0 404 Not Found");
include($website.'/404.shtml');
die;

has done the job for me here

any requests for full filenames ie: this.html or that.gif are not affected by the htaccess rewrites so they're handled 'correctly' anyway.

ta