Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can't get a custom error document to work for 400 Bad Request. It's a CentOS LAMP server.

ErrorDocument 400 /badrdoc.html

I've tried using the above in:

  1. Apache http.conf
  2. Apache httpd-vhosts.conf (in each vhost)
  3. .htaccess in the root htdocs of the site

None of them are working. Apache is serving its default 400 Bad Request page.

Can anyone shed any light on this?

Edit: forgot to mention, I have restarted Apache after changes.

share|improve this question
Did you restart the httpd service ? – Iain Mar 30 '12 at 18:15
@lain, sorry forgot to mention yes I have restarted – ServerBloke Mar 30 '12 at 18:26
Check your /var/log/httpd/error_log for relevant information. – Iain Mar 30 '12 at 18:31
This question suggests that Apache might ignore the ErrorDocument 400 for some requests. – Ladadadada Mar 30 '12 at 18:38
@Ladadadada good link. I am sending a malformed request. Is there no way at all to get my custom 400 doc served? – ServerBloke Mar 30 '12 at 18:44
up vote 3 down vote accepted

I had quite some trouble getting a custom 400 error document to work. I added this to the top level of my Apache conf:

ErrorDocument 404 /404.html
ErrorDocument 400 /400.html

And created the two error documents in the DocumentRoot. First, I tested the 404 with:

echo -en "GET /foo HTTP/1.0\n\n" | nc 80

This returned my custom 404.

Then the 400 (Note that the leading slash is missing):

echo -en "GET foo HTTP/1.0\n\n" | nc 80

The response was the default Apache 400.

I did manage to get my custom 400 back by talking HTTP to an HTTPS vhost:

echo -en "GET / HTTP/1.0\n\n" | nc 443

You still get the same custom 400 back, even if you make an invalid request:

echo -en "GET foo HTTP/1.0\n\n" | nc 443

Unfortunately for your testing, talking SSL to a non-ssl vhost doesn't result in a 400 of any sort. I still haven't figured out how to get a custom ErrorDocuemnt 400 to be sent back on port 80.

P.S. I remember reading somewhere that an ErrorDocument 400 won't work inside a .htaccess file as it may not be possible to even determine the correct DocumentRoot if the request is malformed. The same probably applies to name based virtualhosts.

share|improve this answer
good info thanks. I am causing a malformed request by sending an extra long cookie, to invoke the bad request. In this case I don't think it's possible to serve a custom 400 doc, but it is interesting that it works in the ssl/non ssl case. – ServerBloke Apr 2 '12 at 8:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.