Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

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,

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top