Apache without any error page

5,022

Solution 1

I'm fairly sure you can't do this Apache goes to some lengths to be helpful. From the ErrorDocument documentation

In the event of a problem or error, Apache httpd can be configured to do one of four things,

  1. output a simple hardcoded error message

the rest being custom/local/and remote error documents. Later the documentation says

Additionally, the special value default can be used to specify Apache httpd's simple hardcoded message.

So it appears that the default behaviour is to provide a hard coded ErrorDocument and that you can't override that in the way that you want.

Solution 2

If your Apache has PHP, Perl or any other dynamic extension capable of HTTP header control, then do create a custom page, which responds with the HTTP header fields you want (e.g. by using the PHP header()), but with no other content such as HTML.

Setting ErrorDocument directive to that custom page should produce the result you want.


Note: I'm aware your question asks how to accomplish the response by setting up Apache to serve no error page content and to not use any custom page. The answer above is valid only if you are not constrained to how the actual problem (i.e. giving a HTTP response containing only HTTP header fields) should be solved. Do you really have the constraint that the actual problem (i.e. desired outcome) must not be solved by involving any custom page?

Share:
5,022

Related videos on Youtube

kbec
Author by

kbec

Updated on September 18, 2022

Comments

  • kbec
    kbec over 1 year

    How to set up apache to serve no error page content? I don't want the default behavior, blank or custom page. I want return no content except headers, that all browsers must display own native error page. I'm using Apache 2.2.22

  • kbec
    kbec almost 12 years
    When I use "" the apache reported ErrorDocument takes two arguments, Change responses for HTTP errors on restart. Second solution is just blank page and browser display it either own page. In some random cases my Chrome relly display own errpage, but not always. Maybe if I can change/remove content type it can work, but how?
  • kbec
    kbec almost 12 years
    It's not so good...
  • muskaan sharma
    muskaan sharma over 5 years
    Just set the ErrorDocument to a carriage return, ie., ErrorDocument 403 \r
  • Jpsy
    Jpsy over 4 years
    In my case an empty string for the ErrorDocument response body was not accepted and gave me an internal server error 500. To make it work, I had to enter at least one character, i.e. ErrorDocument 404 " " or ErrorDocument 404 "\n". In the end I chose to return a minimum of plain text information and went like this: ErrorDocument 404 "404 - NOT FOUND" But if you really want to send zero bytes of response body, you have to go with the empty file solution mentioned in the answer.
  • Admin
    Admin almost 4 years
    I know this is an absolutely old post. But you can modify the apache source to remove the hardcoded error page all at once. but I am not sure if we are allowed to modify the source.