[英]A 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request
I'm trying to add a 404 error page to my website, however, I'm getting this error when I try to access it.我正在尝试向我的网站添加 404 错误页面,但是,当我尝试访问它时出现此错误。
Not Found
The requested URL /asd.html 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 .htaccess page contains only the following line:我的 .htaccess 页面仅包含以下行:
ErrorDocument 404 /404-page.php;
And the following 404-page.php file is in the same directory as the .htaccess file, so I'm unsure as to why this is happening.以下 404-page.php 文件与 .htaccess 文件位于同一目录中,因此我不确定为什么会发生这种情况。
<?php
require "header.php";
?>
<main>
<h2>404 - Page not found</h2>
<p>The page you are looking for was not found, if this is an error please contact administration.</p>
</main>
<?php
require "footer.php";
?>
I've tried just using a html page for the 404, as well as uploading the page to a host, but neither has worked.我试过只使用 404 的 html 页面,以及将页面上传到主机,但都没有奏效。
The directory for the host goes:主机目录如下:
/
public_html
404-page.php
.htaccess
Your path may not be the absolute path.您的路径可能不是绝对路径。 Try setting an absolute path ie尝试设置绝对路径即
ErrorDocument 404 /path/to/404/404-page.php
try your http:// path instead of /path/to/404/404-page.php This will depend on your configuration.试试你的 http:// 路径而不是 /path/to/404/404-page.php 这将取决于你的配置。 Please see: http://httpd.apache.org/docs/current/custom-error.html请参阅: http : //httpd.apache.org/docs/current/custom-error.html
the path may not be the absolute path to your htdocs folder root but instead the root of your filesystem.该路径可能不是 htdocs 文件夹根目录的绝对路径,而是文件系统的根目录。 ErrorDocument 404 http://www.domainname.com/404-page.php ; ErrorDocument 404 http://www.domainname.com/404-page.php ;
I fixed the error, turns out it's because I had an ';'我修正了错误,原来是因为我有一个 ';' at the end of the line which is the reason it wasn't working.在行尾,这是它不工作的原因。
转到Apache文件夹中的httpd.conf文件并添加这样的绝对路径
ErrorDocument 404 /nameofyourproject/index.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.