在apache中创build自定义ErrorDocument 404时出错

我有一个在debian上运行apache2的虚拟服务器。 我想在我的所有网站的apache2.conf中创build一个默认的404错误信息。

ErrorDocument 404 "/var/www/site/public/404.html"

重新启动Apache后出现的错误是: Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

它工作,如果我input的url,虽然我不希望页面redirect只使用默认的404.html页面。

您不使用ErrorDocument中的完整path。 它相对于你的htdocs根目录

http://httpd.apache.org/docs/2.0/mod/core.html#errordocument

如果你的根目录是/ var / www / site / public /

 ErrorDocument 404 /404.html 

你也可以做一个完整的url

 ErrorDocument 404 http://domain.com/404.html 

编辑

那么你可以为每个虚拟主机做这个

 Alias /404 /full/path/to/404.html ErrorDocument 404 /404