如何在Apache2中为VirtualHost指定ErrorDocument?

我有一个Apache 2服务器,它有几个具有类似定义的虚拟主机

<VirtualHost *:80> DocumentRoot /var/www/html/host1/ ServerName host1.loc <Directory /var/www/html/host1> AllowOverride FileInfo Options AuthConfig </Directory> ErrorDocument 404 /index.php?error=404 </VirtualHost> <VirtualHost *:80> DocumentRoot /var/www/html/host2/ ServerName host2.loc <Directory /var/www/html/host2> AllowOverride FileInfo Options AuthConfig </Directory> ErrorDocument 404 /index.php?error=404 </VirtualHost> ... <VirtualHost *:80> DocumentRoot /var/www/html/hostN/ ServerName hostN.loc <Directory /var/www/html/hostN> AllowOverride FileInfo Options AuthConfig </Directory> ErrorDocument 404 /index.php?error=404 </VirtualHost> 

我想自定义页面404。

问题是,当我尝试在任何主机上testing404页面时,我可以看到最后一个虚拟主机的页面。 什么可能是错误的我的configuration?

把目录标记中的ErrorDocument指令。

中继: https : //httpd.apache.org/docs/trunk/custom-error.html

2.2: https : //httpd.apache.org/docs/2.2/mod/core.html#errordocument

自定义错误文档是使用ErrorDocument指令configuration的,可以在全局,虚拟主机或目录上下文中使用。 如果AllowOverride设置为FileInfo,则可以在.htaccess文件中使用它。

使用一个HTML文件,而不是一个PHP的。

 ErrorDocument 404 /custom_error_404.html