ErrorDocument 404 not found in non-existent subdomain
- by Question Overflow
I am trying to get the apache server to issue a custom 404 error for invalid subdomains. The following is the relevant part of the httpd configuration:
Alias /err/ "/var/www/error/"
ErrorDocument 404 /err/HTTP_NOT_FOUND.html.var
<VirtualHost *:80> # the default virtual host
ServerName site_not_found
Redirect 404 /
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
ServerAlias ??.example.com
</VirtualHost>
What I get instead is this:
Not Found
The requested URL / was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
I don't understand why a URL to non-existent-subdomain.example.com produces a 404 error without custom error as shown above while a URL to eg.example.com/non-existent-file produces the full custom 404 error.
Can someone advise on this. Thanks.