Posted in Apache Linux

Apache : custom 404 error page returns a 302 error code

July 21, 2007 - 1 comment

First let’s look what the docs says about setting up a custom error page :
http://httpd.apache.org/docs/2.0/en/custom-error.html

If you set up your custom 404 error page pointing to a full URL like :

ErrorDocument 404 http://www.wains.be/404/index.html

You would get an error 302 code.

$ curl -I http://www.wains.be/mlfkgldk
HTTP/1.1 302 Found
Date: Sat, 21 Jul 2007 09:20:40 GMT
Server: Apache
Location: http://www.wains.be/404/index.html
Connection: close
Content-Type: text/html; charset=iso-8859-1

If you want to get the real deal :

ErrorDocument 404 /404/index.html

Then…

$ curl -I http://www.wains.be/mlfkgldk
HTTP/1.1 404 Not Found
Date: Sat, 21 Jul 2007 09:21:16 GMT
Server: Apache
Last-Modified: Sat, 21 Jul 2007 09:19:53 GMT
ETag: "594022-307-8bd8a040"
Accept-Ranges: bytes
Content-Length: 775
Connection: close
Content-Type: text/html; charset=ISO-8859-1

Useful link :

HTTP/1.1 status code definitions available here

Comments

The Adminblogger

July 21, 2007 - 16:25

At the end of your linked documentation there is the explanation for this behaviour:

“Note that the script must emit an appropriate Status: header (such as 302 Found), if the response contains a Location: header (in order to issue a client side redirect). Otherwise the Location: header may have no effect.”

Have a good weekend!

Leave Comment

Please consider visiting the partners below if you enjoyed this article :

If this post saved you time and money, please consider checking my Amazon wishlist.

Before submitting, some rules :
- Is your comment related to the article ?
- You're having a problem ? Have you checked Google, other howtos, docs, manpages ?
- You're still having the problem ? Have you raised log verbosity, checked traces, ran tcpdump ?
- Have you checked your configuratoin for typo ?
Unless your comment is providing additional info or respect the rules above, DON'T comment.
If you don't understand what you are doing, I urge you to read the documentation, I'm not your free Level 1 helpdesk guy.