The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Newer Topic  |  Older Topic 
 Using Error404 Handler to display dynamic content
Author: David van Geyn 
Date:   18-11-01 18:04

Upon reading the brief statement you made about using Error404 for running a PHP script in this article:

I decided to try it out. The problem I found was with Microsoft browsers that were set to 'Use Friendly HTTP Error Messages'. I believe, because the Apache server still sends back a HTTP/1.0 404, Microsoft Internet Explorer then displays it's generic and very simple error message saying the file could not be found. If that option is disabled, it works fine. It also works fine in Netscape, and in Lynx (however, in Lynx, it still does say in the
status bar "File Not Found", then continues and proceeds to load your error page. So, I think the problem is that Microsoft decided to not even display the error message the server produces, and just made its own.

Is there a way to get Apache to send back a 201, or whatever it is, instead of a 404? Or how would one get around this problem? Or can PHP send a second header or something, or one that receeds the Apache 404 header? I'm not really sure how this works...

Thanks for any information you can provide,

David van Geyn

Reply To This Message
 Re: Using Error404 Handler to display dynamic content
Author: David van Geyn 
Date:   21-11-01 20:28

I believe just adding

header("HTTP/1.1 200 OK");

has done the trick.

Reply To This Message
Author: Dan Langille 
Date:   21-11-01 22:36

Can you post code? Provide a URL which demonstrates? Or give me the code to create a demo page. I'll put it on <A HREF=""></A>.

Reply To This Message
 Re: examples?
Author: David van Geyn 
Date:   22-11-01 20:02

That was all the code needed.

If using the ErrorDocument 404 handler to call a PHP script, and you don't want the server sending along an "HTTP/1.1 404 Not Found" header, adding 'header("HTTP/1.1 200 OK");' at the top of your PHP script seems to do the trick.

Reply To This Message
 Re: examples?
Author: Joshua 
Date:   09-12-01 23:39

The problem with sending the 200 code is that the agent then believes it got a valid page. If it's a browser, it gets added to the history list. If it's a spider, the page gets crawled. I'm not sure, but I imagine that it doesn't show up in the server log as an error.

Reply To This Message
 Re: examples?
Author: Dan Langille 
Date:   10-12-01 01:50

A 200 code would only be sent if the URL provided by the user actually resolved to something reasonable. I'll give an example.

The best application of this feature would be for <A HREF="">FreshPorts</A> to allow URLs such as this:

The Error404 handler would invoke a .php page, which would lookup security/logcheck and redirect it to <A HREF="">this page</A>. You'll admit, the above URL is easier than the link just here... In which case, it will return a 200.

If the php script can't find a page to resolve to, it just does The Right Thing (TM) and provides a 404.

Does that makes sense now?

Reply To This Message
 Re: examples?
Author: Joshua 
Date:   11-12-01 19:12

It's early and I've only had one cup of coffee so far, so forgive if this is a thinko...isn't that kind of thing what mod_rewrite is for? Isn't that what FreshPorts is doing?

<a href="">the Apache 1.3 URL Rewriting Guide</a> has all the juicy details.

While writing that, I put back another cup and I still think it's mod_rewrite :)

Reply To This Message
 Re: examples?
Author: Cymen Vig 
Date:   21-04-02 04:54

Simply load a graphic on the 404 page or more text! Microsoft displays their "pretty" 404 error page only when the 404 page loaded is less than a certain number of bytes. I don't remember the particulars but a bit of experimentation should answer the question quickly.

Reply To This Message
 Forum List  |  Threaded View   Newer Topic  |  Older Topic 

 Forum List  |  Need a Login? Register Here 
 User Login
 User Name:
 Remember my login:
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.
How to get the most out of the forum