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!).
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:
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.