1

I have created a number of custom error pages and I have this in global configuration so it will apply to all vhosts:

Alias /common /var/www/common
ErrorDocument 400 /common/400.shtml
ErrorDocument 401 /common/401.shtml
ErrorDocument 403 /common/403.shtml
ErrorDocument 404 /common/404.shtml
ErrorDocument 405 /common/405.shtml
ErrorDocument 408 /common/408.shtml
ErrorDocument 410 /common/410.shtml
ErrorDocument 421 /common/421.shtml
ErrorDocument 500 /common/500.shtml
ErrorDocument 501 /common/501.shtml

Some of these are easier to test than others.

For some of them I had to force the error code using mod_rewrite (RewriteRule ^(.*)$ - [L,R=XXX]) and those all worked as expected

However I'd like to test as many of them "organically" as possible, i.e. inducing the error "for real" rather than forcing it with mod_rewrite. Some of these like 401/403/404 are easily testable in-browser while others like 405 and 501 required Curl and still others required manual telnetting.

The issue I ran into is that when I naturally induce a 400 or 408, Apache seems to ignore my ErrorDoc and serve the default error page:

400 test (sending HTTP/1.1 request without a Host header):

# telnet XXXXX
Trying  XXXXX
Connected to  XXXXX
Escape character is '^]'.
GET / HTTP/1.1

HTTP/1.1 400 Bad Request
Date: Mon, 03 May 2021 16:35:14 GMT
Server: Apache
Content-Length: 546
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<p>Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request.</p>
<hr>
<address>Apache Server at XXXXXX</address>
</body></html>
Connection closed by foreign host.

408 test (not sending a blank line to end the request, waiting for timeout from server instead):

# telnet XXXXX
Trying XXXXX...
Connected XXXX
Escape character is '^]'.
GET / HTTP/1.0
HTTP/1.1 408 Request Timeout
Date: Mon, 03 May 2021 16:27:35 GMT
Server: Apache
Content-Length: 420
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>408 Request Timeout</title>
</head><body>
<h1>Request Timeout</h1>
<p>Server timeout waiting for the HTTP request from the client.</p>
<hr>
<address>Apache Server at XXXXXX</address>
</body></html>
Connection closed by foreign host.
#

Interestingly the server is saying "charset=iso-8859-1" for these -- I'm used to seeing "charset=utf-8" because I have "AddDefaultCharset utf-8" in global config and all my files are UTF-8.

Apache/2.4.41

0 Answers0