Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I think what I was asking for was a bit hard to understand, so, I am trying to make it simpler...

I need my server to have a custom 400 error page when it receives a request with a malformed host header.

What I ideally want is ErrorDocument 400 \somepage.php

I can generate 400 errors by visiting a page such as http:\\myserver\bla%bla, and this will go to my script fine. Likewise, I can change the \somepage.php section to Test text and Apache will return that text.

If however, the 400 error is due to a malformed host header, it will work with the text but not the web page.

Can anyone shed any light on this and give a working solution before I loose all my hair?! (already lost quite a bit over this!).

share|improve this question
    
What exactly does the error log say ? Have you correlated it with the access logs ? Do a TCP dump of the traffic, and show what is really sent over the wire. We need more information to be able to help. –  adaptr Mar 8 '12 at 9:47
    
Yes I have... I thought that was enough information that I gave - the request has invalid headers and Apache returns in the error log - "Client sent malformed Host header", along with a standard 400 error in the access.log .... And again, a string gets returned.... just not a page... If you do need more information, I am happy to give it, but, I am not sure it is needed... I am almost certain the error is just that it can't locate the custom error, I just can't figure out how to actually process it! –  William Hilsum Mar 8 '12 at 11:21

1 Answer 1

up vote 0 down vote accepted

After trying many things, it turns out that this isn't possible.

I opened a ticket on HTTPD's Bug Tracker - which was closed with Won't Fix.

They say that:

Marking as wontfix, when a request is malformed, the server isn't willing to do further processing to serve a custom errordocument out of the filesystem (your error page should have told you a recursive 400 was encountered)

In my opinion, this isn't very good - I understand this being the default action, but, why not let a user use a different page if they so wish.

Quite frankly, it should work this way, but, if anyone comes up with an answer that involves any other technique (proxy, rewrite/similar), I will be happy to look at it and possibly give that the answer mark.


edit

In the end, I found out that it is possible to do this with Nginx and a custom directive to redirect 400 pages. I do not understand why Apache Devs won't acknowledge this, but, Nginx did it fine.

share|improve this answer

Your Answer

 
discard

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.