php 尝试使用 ErrorDocument 时出现 404 Not Found 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12760351/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:10:44  来源:igfitidea点击:

Getting 404 Not Found error while trying to use ErrorDocument

phpapache.htaccesshttp-status-code-404

提问by user1725155

I know this thread has been talked a lot on the web and here, and I tried almost all the methods, but still I'm having the same problem.

我知道这个线程已经在网上和这里讨论了很多,我尝试了几乎所有的方法,但我仍然遇到同样的问题。

This is my url on my local server ( MAMP )

这是我在本地服务器 ( MAMP ) 上的网址

http://localhost:8888/hellothere/index.php

And I've tried to insert a wrong path to take me to wrong page , like below :

而且我试图插入错误的路径以将我带到错误的页面,如下所示:

http://localhost:8888/hellothere/eiurgiuerib

Instead of taking me to Error Page it shows :

它没有将我带到错误页面,而是显示:

Not Found

The requested URL /hellothere/eiurgiuerib was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

My 404 page is inside of the Error directory. And inside my .htaccess file I have included this :

我的 404 页面位于 Error 目录中。在我的 .htaccess 文件中,我包含了这个:

ErrorDocument 404 /Error/404.php

回答by StaticVariable

The ErrorDocumentdirective, when supplied a local URL path, expects the path to be fully qualified from the DocumentRoot. In your case, this means that the actual path to the ErrorDocumentis

ErrorDocument指令在提供本地 URL 路径时,期望该路径完全符合DocumentRoot. 在您的情况下,这意味着实际路径ErrorDocument

ErrorDocument 404 /hellothere/error/404page.html

回答by karthik k

When we apply local url, ErrorDocument directive expect the full path from DocumentRoot. There fore,

当我们应用本地 url 时,ErrorDocument 指令需要来自 DocumentRoot 的完整路径。所以,

 ErrorDocument 404 /yourfoldernames/errors/404.html