在不存在的子域中找不到ErrorDocument 404

我试图让Apache服务器发出无效子域的自定义404错误。 以下是httpdconfiguration的相关部分:

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> 

我得到的是这样的:

未find

在此服务器上找不到请求的URL /。

此外,尝试使用ErrorDocument处理请求时遇到404 Not Found错误。

我不明白为什么一个URL non-existent-subdomain.example.com产生404错误没有自定义错误,如上所示,而一个URL到eg.example.com/non-existent-file产生完整的自定义404错误。

有人可以build议这一点。 谢谢。

有趣; 该语法仅被logging为与410状态码一起使用。

无论如何,使用Redirect 404 /解释了无法提供自定义错误页面 – 它也受到Redirect的影响。

404虚拟主机提供自己的空DocumentRoot是一种select,因为它可以“正常” 404请求,而不会将其全部应用于虚拟主机中的所有内容(包括错误页面)。

或者,如果Redirect适用于404,也许RedirectMatch也可以?

 RedirectMatch 404 ^/(?!err)