HTTP Error Codes

From HE FAQ
Revision as of 08:50, 8 September 2009 by Dean (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

What is an HTTP response code?

HTTP response codes are the standard numbers associated web server error messages.

An example is:

404 Error: File not found


What does "Code 404: Not found" mean?

It means that you had a request for a document in your site that did not exist. Typically this is the result of a bad URL in one of your documents which links to a non existent document, either a mistake, or one that you were planning on writing but haven't yet.


What does Code 302 mean?

Code 302 Redirected requests result whenever you specify a directory for a URL. For example, if you specify:

http://www.he.net/~rflyer

the server redirects the browser to request:

http://www.he.net/~flyer/index.html

The server handles the redirection in this manner in conformance with HTTP standards. It is quite normal.


How do I customize error messages like "Code 404: Not Found"?

You can customize your error messages by creating or editing your .htaccess file. But first you need to create the following html documents:

  • 400.html
  • 401.html
  • 403.html
  • 404.html
  • 500.html

You can word the contents of these documents however you please.

Now comes your .htaccess file. Inside your public_html directory, or one of its subdirectories, you may have a file named .htaccess. If an .htaccess file isn't already there, then you can either create one online using the pico command in ssh, or create one in a text editor and upload it to the server using an ftp program. Now add the following lines to your .htaccess file.


ErrorDocument 400 URL
ErrorDocument 401 URL
ErrorDocument 403 URL
ErrorDocument 404 URL
ErrorDocument 500 URL

Make sure to replace where it says URL with the URL to that error message.

For example, your .htaccess file may look something like this:

ErrorDocument 400 /400.html
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html

If you do not have your domain pointed to your account, you must use the fully qualified URL, like this:

ErrorDocument 400 http://he.net/~jdoe/400.html
ErrorDocument 401 http://he.net/~jdoe/401.html
ErrorDocument 403 http://he.net/~jdoe/403.html
ErrorDocument 404 http://he.net/~jdoe/404.html
ErrorDocument 500 http://he.net/~jdoe/500.html

You also have the option of just puting in the text or HTML to display in your .htaccess file.

For example:

ErrorDocument 404 "<h2><i>404 Error:</i> File not found</h2>"

Note that when you specify an ErrorDocument that points to a remote URL (ie. anything with a method such as "http" in front of it) Apache will send a redirect to the client to tell it where to find the document, even if the document ends up being on the same server. This has several implications, the most important being that if you use an "ErrorDocument 401" directive then it must refer to a local document. This results from the nature of the HTTP basic authentication scheme.