本文介绍了Apache的自定义404错误问题-ErrorDocument也是404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的网站创建一个自定义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:


推荐答案

指令在提供本地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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

查看更多