views:

583

answers:

5

I am building a simple HTTP server for a project. Most websites have custom 404 error pages. Sometimes though, you'll see Firefox spitting a generic 404 page (or 405, etc...). How does it decide what to do? What should the HTTP response be? Is "HTTP/1.0 404 NOT FOUND" enough?

Thanks

A: 

Usually it set up in the webserver, ie: When the server gets a 404, refer it to this page.

Ian Jacobs
What if you want Firefox to spit out a generic error page?
nute
As far as I know, the only browser that has a generic error page is MSIE.
David Dorward
+1  A: 

So, Firefox won't show a generic 404 error page under most circumstances; you're thinking of Internet Explorer, which ignores a website's 404 page if it's below a certain size and displays its own.

Edward Z. Yang
what about other error numbers? Is the server supposed to send custom page for all, or can the browser handle that?
nute
+1  A: 

If you are creating an HTTP server you might want to look at the RFC that describes the protocol: http://www.faqs.org/rfcs/rfc2616.html

For the 404 status code it says:

The server has not found anything matching the Request-URI. No
indication is given of whether the condition is temporary or
permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable.

You can't control how the browser will treat each status code, you shuld rely on its good behaviour.

That said, you may benefit from using one of the existing HTTP servers. Look at this question on how to create an HTTP server in C or C++ posted few days ago,

Remo.D
+1  A: 

It is perfectly valid to return an html body with a 404 response code. If no body is provided then the browser will show a default page.

  1. If you only send HTTP/1.0 404 NOT FOUND then the browser default will be displayed.
  2. If you add a body to the response the browser will mostly use that.
johnstok
To be picky, it's not the html body that contains the 404 response, it's the HTTP header ...
Remo.D
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4 - the server SHOULD include a body explaining the error.
David Dorward
The header contains the error code, the body contains the human-readable error message.
artur02
+3  A: 

If server can't find the requested resource (e.g. a webpage), it sends an HTTP/1.0 404 NOT FOUND in the HTTP header section.

Servers can map an error page for this error, so you can get a readable error page. Browsers can also map an own error page, so you can see a browser-specific error 404 message.

You can see the error code in the status field in log files.

You can redirect your user to a specific page with this structure:

<HTML>
<head>
<meta HTTP-EQUIV="Refresh" CONTENT="5; URL=not404.htm">
</head>
</HTML>

See details on Welcome to 404 Error Pages .com

artur02