Wednesday, August 31, 2022

[SOLVED] What is location for standard Apache Error Document for 404?

Issue

I am working on customizing various error codes for apache and I know the way to do it. (By adding new pages and referencing them in the /etc/httpd/conf/httpd.conf against the various error codes.

My question here is - where does the standard error message for apache come from? For example if I run my local apache and try to browse a non existing URL, I get following error.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /not_found was not found on this server.</p>
<hr>
<address>Apache/2.2.15 (CentOS) Server at localhost Port 80</address>
</body></html>

My httpd.conf does not have any ErrorDocument overrides. So this is standard apache error. When I grep, I don't find any file containing these texts.

So does that mean this is coming from an apache module?


Solution

Answering my own question:

The error comes from "c" file and apache does not have an default error html as I thought initially. Httpd source can be http://httpd.apache.org/download.cgi.

Refer to "src\main\http_protocol.c" file and below is code that throws 404 exception with the given message.

case NOT_FOUND:
        ap_rvputs(r, "The requested URL ",
              ap_escape_html(r->pool, r->uri),
              " was not found on this server.<P>\n", NULL);
        break;


Answered By - user1401472
Answer Checked By - David Marino (WPSolving Volunteer)