【问题标题】:.htaccess file can't find 404 ErrorDocument.htaccess 文件找不到 404 ErrorDocument
【发布时间】:2013-01-04 01:06:45
【问题描述】:

我拥有的 .htaccess 文件无法在名为“error”的子文件夹中找到我的 404.html 文档。特别是:

ErrorDocument 404 /error/404.html

但是,如果我将 404.html 放在与 .htaccess 相同的目录中并将行更改为:

ErrorDocument 404 /404.html --- 有效!

如果有帮助,我正在使用 XAMPP for Windows,并且在我的 httpd.conf 文件中,相关指令设置如下(我意识到存在一些冗余):

<Directory />
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

<Directory "C:/xampp/htdocs">
    Options Indexes FollowSymLinks Includes ExecCGI MultiViews
    AllowOverride All
    Require all granted
</Directory>

另外,我的 DocumentRoot 设置为“C:/xampp/htdocs”,并且我尝试了各种路径来访问“错误”目录--无济于事:

ErrorDocument 404 /error/404.html
ErrorDocument 404 /flchi/error/404.html
ErrorDocument 404 /sites/flchi/error/404.html
ErrorDocument 404 /htdocs/sites/flchi/error/404.html

哦,最后一件事是值得的——我正在使用虚拟主机。以下是相关位:

<VirtualHost *>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
    ServerAlias localhost
    <Directory "C:/xampp/htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost flchi.local>
    DocumentRoot "C:/xampp/htdocs/sites/flchi"
    ServerName flchi.local
    ServerAlias flchi.local
    <Directory "C:/xampp/htdocs/sites/flchi">
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

【问题讨论】:

  • 您尝试使用的文件404.html 的绝对路径是什么,您的.htaccess 在哪个目录中?
  • 404.html的绝对路径:“C:/xampp/htdocs/sites/flchi/error/404.html”。 .htaccess 所在的目录是:/flchi.

标签: apache .htaccess xampp http-status-code-404


【解决方案1】:

发生这种情况是因为命名冲突 - 默认 Apache 配置已经为 /error 定义了虚拟路径,这会影响全局的所有虚拟主机。它在配置文件xampp/apache/conf/extra/httpd-multilang-errordoc.conf 中完成。位置 /error,因此会影响您的 /error 子目录:

  Alias /error/ "C:/xampp/apache/error/"

如果您将“错误”子目录重命名为其他名称,它应该可以工作 - 例如,error2

   ErrorDocument 404 /error2/404.html

【讨论】:

  • 宾果游戏,就是这样!我将目录更改为“站点错误”并且一切正常!谢谢!
猜你喜欢
  • 2018-01-03
  • 2014-05-23
  • 2012-08-25
  • 2011-12-01
  • 2021-06-10
  • 2013-11-07
  • 2013-02-10
  • 1970-01-01
  • 2016-02-16
相关资源
最近更新 更多