问题描述
我正在尝试为我的网站创建自定义 404 错误.我正在 Windows 上使用 XAMPP 对此进行测试.
I am trying to create a custom 404 error for my website. I am testing this out using XAMPP on Windows.
我的目录结构如下:
error\404page.html
index.php
.htaccess
我的 .htaccess 文件的内容是:
The content of my .htaccess file is:
ErrorDocument 404 error\404page.html
这会产生以下结果:
但是这不起作用 - 是否与斜线的方式有关,或者我应该如何引用错误文档?
However this is not working - is it something to do with the way the slashes are or how I should be referencing the error document?
站点文档驻留在 web 根目录的子文件夹中,如果这对我应该如何引用有任何影响?
site site documents reside in a in a sub folder of the web root if that makes any difference to how I should reference?
当我将文件更改为
ErrorDocument 404 /error/404page.html
我收到以下错误消息,这不是我链接的 html 文件中的内容 - 但与上面列出的不同:
I receive the following error message which isn't what is inside the html file I have linked - but it is different to what is listed above:
推荐答案
ErrorDocument
指令,当提供本地 URL 路径时,期望路径完全符合 DocumentRoot
.在您的情况下,这意味着 ErrorDocument
的实际路径是
ErrorDocument 404 /JinPortfolio/error/404page.html
当您在第二次尝试中更正它时,您看到该页面的原因是因为 http://localhost/error/404page.html
不存在,因此有点关于存在定位错误处理文档时出现 404 错误.
When you corrected it in your second try, the reason you see that page instead is because http://localhost/error/404page.html
doesn't exist, hence the bit about there being a 404 error in locating the error handling document.
这篇关于Apache 的自定义 404 错误问题 - ErrorDocument 也是 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!