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, ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
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/ |
|
|||
|
> 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. |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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/ |