【问题标题】:Apache does NOT search parent folders for .htaccessApache 不会在父文件夹中搜索 .htaccess
【发布时间】:2016-07-27 20:19:12
【问题描述】:

如您所知,如果父文件夹有 .htaccess 文件,apache2 应该将 .htaccess 应用于子文件夹。我的问题是这不会发生。

我有文件夹:

/var/www/program
/var/www/program/rec
/var/www/program/rec2

我希望rec 和rec2 继承程序的.htaccess。这不会发生。

程序的.htaccess是:

RewriteOptions inherit
RewriteEngine On
RewriteRule ^$ example.php

https://www.example.com/program 根据需要重定向到https://www.example.com/program/example.php

由于某种原因,这两个子文件夹不会发生这种情况。没有应用重写规则。

如果我将 .htaccess 放在子文件夹 rec 中,则可以按预期工作,但 rec2 仍然不会重定向。

我在任何其他父文件夹中都没有其他 .htaccess。我的 /etc/apache2/sites-enabled/000-default 包含以下内容:

<VirtualHost *:443>
    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM

    SSLCertificateFile /etc/apache2/ssl/ssl.crt
    SSLCertificateKeyFile /etc/apache2/ssl/private.key
    SSLCertificateChainFile /etc/apache2/ssl/server.ca.pem
    ServerAdmin webmaster@localhost
    Redirect /deluge https://www.example.com:8000
    Redirect /d https://www.example.com:8000
    RewriteOptions inherit

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www/>
        RewriteOptions inherit
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride All
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
    Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

我已经尝试了一天来解决这个问题。

【问题讨论】:

    标签: .htaccess mod-rewrite apache2


    【解决方案1】:

    问题在于 RewriteRule 假定 root 是 .htaccess 的位置,而不是当前文件夹。

    以下代码解决了我的问题。

    RewriteOptions inherit
    RewriteEngine On
    RewriteRule /?$ example.php
    

    这篇文章对我有帮助:

    .htaccess RewriteRule not working in subdirectory

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-02
      • 1970-01-01
      • 2013-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多