设置404页面显示404文件名

setting 404 page displays the name of 404 file

我编辑了我网站上的 .htaccess 文件,并添加了行

ErrorDocument 404 page-not-found.html

所以当我输入 example.com/pagethatdoesntexist 时,屏幕只显示“page-not-found.html”。为什么会这样?

根据 Apache reference 文档,对于本地 web-paths(相对于 DocumentRoot),URLs 可以以斜杠 (/) 开头,或者是完整的 URL 客户端可以解决。

所以在你的情况下,这应该可以完成工作。

ErrorDocument 404 /page-not-found.html

如果没有/,您的网页名称将被视为消息并打印在浏览器中。