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

Joh*_*lia 5 debian web-server apache-2.2

我有一个在 debian 上运行 apache2 的虚拟服务器。我想在 apache2.conf 中为我的所有网站创建一个默认的 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.

虽然我不希望页面重定向只使用默认的 404.html 页面,但如果我输入 URL,它会起作用。

Mik*_*ike 6

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

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

如果您的根是 /var/www/site/public/

ErrorDocument 404 /404.html
Run Code Online (Sandbox Code Playgroud)

你也可以做一个完整的网址

ErrorDocument 404 http://domain.com/404.html
Run Code Online (Sandbox Code Playgroud)

编辑

您可以为每个虚拟主机执行此操作

Alias /404 /full/path/to/404.html
ErrorDocument 404 /404
Run Code Online (Sandbox Code Playgroud)