homepage Welcome to WebmasterWorld Guest from 54.166.8.138
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
header "404 Not Found"
el_roboto




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

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?

 

whoisgregg




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

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;

phranque




msg:3560912
 2:31 pm on Jan 29, 2008 (gmt 0)

have you specified your custom 404 document in the configuration?

ErrorDocument 404 /404.shtml

Nutter




msg:3560918
 2:36 pm on Jan 29, 2008 (gmt 0)

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()

mipapage




msg:3560983
 3:32 pm on Jan 29, 2008 (gmt 0)

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.

phranque




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

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.

el_roboto




msg:3561017
 4:06 pm on Jan 29, 2008 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved