I am trying to see if a custom error page can be sent to the browser when an invalid method is sent to the server.

In my .htaccess is this:

ErrorDocument 400 /errpages/httperror.php
ErrorDocument 401 /errpages/httperror.php
ErrorDocument 403 /errpages/httperror.php
ErrorDocument 404 /errpages/httperror.php
ErrorDocument 405 /errpages/httperror.php

RewriteEngine on
RewriteRule .* - [R=405,L]

It works as expected, and while using Postman to create a HEAD request I receive the expected 405 response in the header.

However, what I want is the 405 error page not just the header. Is it possible to modify what I have to make that happen?

1 Answer 1


Not all request methods will receive a response body as part of the HTTP response.

The webserver does not (should not) send back a response body in response to a HEAD request (and any user-agent should discard it if it does), so that's why you are not seeing your error document as part of the response in your example. The same with PUT and TRACE requests (although servers vary). For other request methods you should see your error document in the response body (although what the user-agent does with this is another matter).

This has nothing to do with the 405 response you are sending back, the same would apply to any other HTTP response code.

  • 2
    To back that up with a reference, datatracker.ietf.org/doc/html/rfc7231#section-4.3.2 (Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content) says: "The HEAD method is identical to GET except that the server MUST NOT send a message body in the response (i.e., the response terminates at the end of the header section)." May 31, 2022 at 0:05
  • @MrWhite Thank you for the explanation. and thank you Patrick Mevzek for the link to the docs. It all makes sense to me now.
    – jxmot_wd
    Jun 1, 2022 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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