|
Home > Archive > Web Servers on Unix and Linux > May 2005 > trigger default Apache 404 error from PHP
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
trigger default Apache 404 error from PHP
|
|
| humbads 2005-05-02, 2:46 am |
| 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 in my CMS 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 dynamic details, like the requested
URL, and I would rather not recreate it for consistency. I asked in the
PHP group and didn't get an answer.
| |
|
| On 2 May 2005 00:35:41 -0700,
"humbads" <humbads@gmail.com> posted:
> 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 in my CMS is requested that is not published, then I want
> to send the apache default 404 error page.
Perhaps it's really some other sort of error response, than 404, that you
should be returning then (forbidden, not authorised, etc.).
> The default 404 error page has more dynamic details, like the requested
> URL, and I would rather not recreate it for consistency. I asked in the
> php group and didn't get an answer.
Simple answer: Use the files that Apache refers to for the 404 notice.
Slightly more complex: Make your own 404 message, and use it for both
straight Apache and php 404 errors (perhaps using php to make your 404
notice, if you're more comfortable with using php features to add dynamic
data to the error message). Apache's default 404 message is rather
esoteric and doesn't really help a lot of people who don't understand what
a 404 error is about.
--
If you insist on e-mailing me, use the reply-to address (it's real but
temporary). But please reply to the group, like you're supposed to.
This message was sent without a virus, please delete some files yourself.
| |
| humbads 2005-05-05, 2:46 am |
| > How can I trigger the default Apache 404 error from PHP?
> Simple answer: Use the files that Apache refers to for the 404
notice.
I asked my server admin, and he said that 404 is being generated from
code built-in to the Apache binaries. If that is the case, I can not
do a simple redirect or fopen. You are right that I should make a more
useful 404 error page for my users, maybe with a Google site-search
box. On the other hand, I'd really like to satisfy my curiosity to
know if there is a mechanism to transfer control over the HTTP request
from php back to Apache.
| |
|
| an unattributed author:
Tim wrote:
[vbcol=seagreen]
"humbads" <humbads@gmail.com> posted:
[vbcol=seagreen]
> I asked my server admin, and he said that 404 is being generated from
> code built-in to the Apache binaries.
Depends on the server. For the version I'm play with, there's a
/var/www/errors/ directory with multi-lingual error messages. Mine uses
/var/www/errors/HTTP_NOT_FOUND.html.var for 404 errors, by default.
> On the other hand, I'd really like to satisfy my curiosity to
> know if there is a mechanism to transfer control over the HTTP request
> from php back to Apache.
Well, since you can specify the page returned with a 404 error in Apache, I
would have thought php and Apache had something similar in the other
direction. Though, seeing some of the awful things that happen with PHP, I
wouldn't be surprised if they've forgotten to allow the obvious.
--
If you insist on e-mailing me, use the reply-to address (it's real but
temporary). But please reply to the group, like you're supposed to.
This message was sent without a virus, please delete some files yourself.
|
|
|
|
|