send default apache 404 error from php

This is a discussion on send default apache 404 error from php within the PHP Language forums, part of the PHP Programming Forums category; How can I trigger the default Apache 404 error from PHP? I don't want to specify a custom handler, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2005
humbads@gmail.com
 
Posts: n/a
Default send default apache 404 error from php

How can I trigger the default Apache 404 error from PHP? I don't want
to specify a custom handler, I want the default handler. The reason is
that I am using mod_rewrite with Apache for my site. If certain a
certain page is requested that is not published, then I want to send
the apache default 404 error page. Currently, I am doing this to
return a custom error.

if($pageNotPublished) {
header("HTTP/1.1 404 Not Found");
// How do I send the default apache 404 message
// instead of the message below?
print("<html><body>HTTP 404 - Not Found</body></html>");
exit();
}

The default 404 error page has more details, and I would rather not
recreate it.

Reply With Quote
  #2 (permalink)  
Old 04-24-2005
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Re: send default apache 404 error from php

humbads@gmail.com wrote:
<snip>
> if($pageNotPublished) {
> header("HTTP/1.1 404 Not Found");
> // How do I send the default apache 404 message
> // instead of the message below?
> print("<html><body>HTTP 404 - Not Found</body></html>");


Hmm..What about readfile() here?

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Reply With Quote
  #3 (permalink)  
Old 04-26-2005
humbads@gmail.com
 
Posts: n/a
Default Re: send default apache 404 error from php

> if($pageNotPublished) {
> header("HTTP/1.1 404 Not Found");
> // How do I send the default apache 404 message
> // instead of the message below?
> print("<html><body>HTTP 404 - Not Found</body></html>");


> Hmm..What about readfile() here?


Thanks for your reply. readfile won't work because the 404 message
contains dynamic information like the requested URL. It looks like
this:

Not Found
The requested URL /alkdf was not found on this server.
Apache/1.3.33 Server at mywebsite.com Port 80

Of course, I could recreate it using PHP functions, but for
consistency, I'd rather have PHP pass through to Apache's default 404
error handler. I think this is a tough question, any experts want to
take it? In the meantime, I'll cross post my question in the Apache ng.

Reply With Quote
  #4 (permalink)  
Old 04-26-2005
Micha³ Wo¼niak
 
Posts: n/a
Default Re: send default apache 404 error from php

One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable humbads@gmail.com's handwriting:

>> if($pageNotPublished) {
>> header("HTTP/1.1 404 Not Found");
>> // How do I send the default apache 404 message
>> // instead of the message below?
>> print("<html><body>HTTP 404 - Not Found</body></html>");

>
>> Hmm..What about readfile() here?

>
> Thanks for your reply. readfile won't work because the 404 message
> contains dynamic information like the requested URL. It looks like
> this:
>
> Not Found
> The requested URL /alkdf was not found on this server.
> Apache/1.3.33 Server at mywebsite.com Port 80
>
> Of course, I could recreate it using PHP functions, but for
> consistency, I'd rather have PHP pass through to Apache's default 404
> error handler. I think this is a tough question, any experts want to
> take it? In the meantime, I'll cross post my question in the Apache
> ng.


What about $err404=readfile('some/non-existant.file');
str_replace('some/non-existant.file', 'your_file', $err404);?
:)

Cheers
Mike
Reply With Quote
  #5 (permalink)  
Old 04-26-2005
Micha³ Wo¼niak
 
Posts: n/a
Default Re: send default apache 404 error from php

One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable Micha³ Wo¼niak's handwriting:

> One quick glance of an experienced eye allowed to understand the
> blurred and almost unreadable humbads@gmail.com's handwriting:
>
>>> if($pageNotPublished) {
>>> header("HTTP/1.1 404 Not Found");
>>> // How do I send the default apache 404 message
>>> // instead of the message below?
>>> print("<html><body>HTTP 404 - Not Found</body></html>");

>>
>>> Hmm..What about readfile() here?

>>
>> Thanks for your reply. readfile won't work because the 404 message
>> contains dynamic information like the requested URL. It looks like
>> this:
>>
>> Not Found
>> The requested URL /alkdf was not found on this server.
>> Apache/1.3.33 Server at mywebsite.com Port 80
>>
>> Of course, I could recreate it using PHP functions, but for
>> consistency, I'd rather have PHP pass through to Apache's default 404
>> error handler. I think this is a tough question, any experts want to
>> take it? In the meantime, I'll cross post my question in the Apache
>> ng.

>
> What about $err404=readfile('some/non-existant.file');
> str_replace('some/non-existant.file', 'your_file', $err404);?
> :)
>
> Cheers
> Mike


Ooops, sorry, readfile reads the file into the buffer... My mistake.

Cheers
Mike
Reply With Quote
  #6 (permalink)  
Old 04-28-2005
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Re: send default apache 404 error from php

humbads@gmail.com wrote:
> > if($pageNotPublished) {
> > header("HTTP/1.1 404 Not Found");
> > // How do I send the default apache 404 message
> > // instead of the message below?
> > print("<html><body>HTTP 404 - Not Found</body></html>");

>
> > Hmm..What about readfile() here?

>
> Thanks for your reply. readfile won't work because the 404 message
> contains dynamic information like the requested URL. It looks like
> this:
>
> Not Found
> The requested URL /alkdf was not found on this server.
> Apache/1.3.33 Server at mywebsite.com Port 80
>
> Of course, I could recreate it using PHP functions, but for
> consistency, I'd rather have PHP pass through to Apache's default 404
> error handler. I think this is a tough question, any experts want to
> take it?


I think, Chung Leong can answer your question--he was hacking Apache
for sometime ago.

> In the meantime, I'll cross post my question in the Apache ng.


Yes, that might help.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:01 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0