473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

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.

Jul 17 '05 #1
5 9034
hu*****@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/

Jul 17 '05 #2
> 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.

Jul 17 '05 #3
One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable hu*****@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
Jul 17 '05 #4
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 hu*****@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
Jul 17 '05 #5
hu*****@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/

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: mr_burns | last post by:
Hi, i am getting the following errors when running my php script: Warning: Cannot send session cookie - headers already sent by (output started at ...
2
by: Sam Hou | last post by:
Dear all, I don't know where my problem is. Hopefully someone can give me some hint to explore the problem more. I am running Apache 2.0.48 wih PHP 4.3.4. The apache is running as nobody. I...
1
by: SPG | last post by:
Hi, I am relatively new to TOMCAT, and am trying to deploy a web app using it. I have a domain name that I want to use to access my web app directly. By default, I deploy my WAR, and it deploys...
2
by: Lisa Pearlson | last post by:
Hi, My php application (on Apache/Linux) needs to do the following: The PHP script receives a request from a client (binary), asking for certain records of data. My PHP script loops through...
4
by: Patrick Masson | last post by:
Hello, Our configuration : Apache 2.0.53 PHP 5.0.4 PC Windows 2000 MATLAB 6.1 We work on a consulting project in France which involves MATLAB Web server,
0
by: Alexiel | last post by:
Hi, i have a problem, I have a Java Client and i call my webservice on ..NET. This run perfectly just except when i send parameters don't work fine. I send my code : This is my java...
7
by: oopsbabies | last post by:
Hello everyone, I am using Apache 1.3.33 as the web server and PHP version 4.3.10. My machine is using Windows XP 2002 professional edition which comes with a Windows firewall. I am using McAfee...
1
Osoascam
by: Osoascam | last post by:
Hi! I'm trying to do a simple JDOM example, as I have to uste it for a homework... The thing is, it just doesn't work... See, this is the code: public class Ejemplo { public static void...
2
by: btcoder | last post by:
Hi, my jsp page uses sun.net.smtp.SmtpClient to send email. It worked fine until the hosted location was moved to another server. Now it generates the sun.net.smtp.SmtpProtocolException and the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.