【问题标题】:.htaccess in parent directory causing ErrorDocument in subdirectory to not work父目录中的 .htaccess 导致子目录中的 ErrorDocument 不起作用
【发布时间】:2017-01-25 15:49:31
【问题描述】:

我有一个指向它自己的域的子目录,所以我希望它有自己的 404 页面。子目录中的 .htaccess 内容如下:

ErrorDocument 404 /subdirectory/404.html

我觉得这应该可以,但是有一个问题。父目录有wordpress的安装,所以.htaccess如下

# Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
# Set PHP handler to application/x-httpd-phpbeta on Mon Jan 11 15:10:53 MST 2016.

如果子目录中有 index.php,则用作 404 页面。 否则,无论子文件夹中的 .htaccess 是否存在,我都会收到 500 错误。是什么阻止了我的 .htaccess 工作?

【问题讨论】:

  • 自定义错误信息是否有效?试试 ErrorDocument 404 "抱歉找不到页面"
  • 不,我仍然得到 404。糟透了。

标签: php wordpress .htaccess http-status-code-404


【解决方案1】:

您需要在/subdirectory/.htaccess 中添加RewriteEngine On 行来覆盖父目录的重写规则。你的/subdirectory/.htaccess 会变成这样:

ErrorDocument 404 /subdirectory/404.html

RewriteEngine On

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-10
    • 2015-02-19
    • 2012-03-23
    • 2011-10-13
    • 1970-01-01
    • 2015-11-12
    相关资源
    最近更新 更多