Connecting Tech Pros Worldwide Forums | Help | Site Map

send default apache 404 error from php

humbads@gmail.com
Guest
 
Posts: n/a
#1: Jul 17 '05
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.


R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#2: Jul 17 '05

re: send default apache 404 error from php


humbads@gmail.com wrote:
<snip>[color=blue]
> 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>");[/color]

Hmm..What about readfile() here?

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

humbads@gmail.com
Guest
 
Posts: n/a
#3: Jul 17 '05

re: send default apache 404 error from php


> if($pageNotPublished) {[color=blue]
> 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>");[/color]
[color=blue]
> Hmm..What about readfile() here?[/color]

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.

Micha³ Wo¼niak
Guest
 
Posts: n/a
#4: Jul 17 '05

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:
[color=blue][color=green]
>> 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>");[/color]
>[color=green]
>> Hmm..What about readfile() here?[/color]
>
> 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.[/color]

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

Cheers
Mike
Micha³ Wo¼niak
Guest
 
Posts: n/a
#5: Jul 17 '05

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:
[color=blue]
> One quick glance of an experienced eye allowed to understand the
> blurred and almost unreadable humbads@gmail.com's handwriting:
>[color=green][color=darkred]
>>> 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>");[/color]
>>[color=darkred]
>>> Hmm..What about readfile() here?[/color]
>>
>> 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.[/color]
>
> What about $err404=readfile('some/non-existant.file');
> str_replace('some/non-existant.file', 'your_file', $err404);?
> :)
>
> Cheers
> Mike[/color]

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

Cheers
Mike
R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#6: Jul 17 '05

re: send default apache 404 error from php


humbads@gmail.com wrote:[color=blue][color=green]
> > 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>");[/color]
>[color=green]
> > Hmm..What about readfile() here?[/color]
>
> 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?[/color]

I think, Chung Leong can answer your question--he was hacking Apache
for sometime ago.
[color=blue]
> In the meantime, I'll cross post my question in the Apache ng.[/color]

Yes, that might help.

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

Closed Thread