【问题标题】:A 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误
【发布时间】:2020-06-06 19:08:09
【问题描述】:

我正在尝试将 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.

我的 .htaccess 页面仅包含以下行:

ErrorDocument 404 /404-page.php;

而且下面的 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";
    ?>

我试过只为 404 使用 html 页面,以及将页面上传到主机,但都没有成功。

主机的目录去:

/
 public_html
   404-page.php
   .htaccess

【问题讨论】:

  • 您是否尝试过检查htaccess 是否已被解析,例如通过在其中放入无效字符串?
  • @NicoHaase 我只是尝试放置一个无效的路径,然后返回 命令的一部分,例如路径/404-page.php

标签: php html .htaccess


【解决方案1】:

路径可能不是您的 htdocs 文件夹根目录的绝对路径,而是文件系统的根目录。 错误文档 404 http://www.domainname.com/404-page.php;

【讨论】:

    【解决方案2】:

    您的路径可能不是绝对路径。尝试设置绝对路径,即

    ErrorDocument 404 /path/to/404/404-page.php
    

    试试你的 http:// 路径而不是 /path/to/404/404-page.php 这将取决于您的配置。请看:http://httpd.apache.org/docs/current/custom-error.html

    【讨论】:

    【解决方案3】:

    我修复了错误,原来是因为我有一个';'在行尾,这就是它不起作用的原因。

    【讨论】:

      【解决方案4】:

      转到 Apache 文件夹中的 httpd.conf 文件并添加这样的绝对路径

      ErrorDocument 404 /nameofyourproject/index.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-11-27
        • 1970-01-01
        • 2012-09-27
        • 2017-10-19
        • 2017-08-27
        • 2016-08-07
        • 2016-02-01
        相关资源
        最近更新 更多