.htaccess文件找不到404 ErrorDocument

时间:2013-01-21 00:06:51

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

我的.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>

1 个答案:

答案 0 :(得分:4)

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

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

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

   ErrorDocument 404 /error2/404.html