【问题标题】:Subfolder .htacess not overriding parent .htacess options子文件夹 .htaccess 不覆盖父 .htaccess 选项
【发布时间】:2019-01-31 22:43:34
【问题描述】:

我的域根目录上有一个 .htacess,用于将所有流量重定向到 index.php

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

#redirect http to https, remove www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

#remove index.php from link
RewriteRule ^index.php$ - [L] 

#redirect to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

</IfModule>

#remove direct access to all *.php except index.php
<Files *.php>
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Files>

<Files index.php>
    Order Allow,Deny
    Allow from all
</Files>

一切都按预期工作,流量被重定向,当文件存在时显示文件。

现在我有一个管理文件夹 /admin/ 和 index.php 和 api.php 我可以打开 /admin/ 和 /admin/index.php 但 /admin/api.php 重定向到 /index.php

我尝试在 /admin/ 中放置一个 .htaccess,如下所示:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine Off
RewriteEngine On

#redirect http to https, remove www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

</IfModule>

但得到相同的结果。 /admin/ 打开,但 /admin/api.php 重定向到索引

【问题讨论】:

    标签: apache .htaccess redirect


    【解决方案1】:

    找到问题/解决方案。

    需要添加到/admin/里面的.htaccess

     <Files *>
        Order Allow,Deny
        Allow from all
    </Files>
    

    【讨论】:

    • 对不起,这与您报告的问题无关。您遇到的实际问题是根文件夹中的配置被评估 first 并将所有内容重定向到 relative 路径index.php,因此文件夹内的索引文件是请求。这就是为什么对/admin/api.php 的请求也被重定向到/admin/index.php
    猜你喜欢
    • 2013-10-14
    • 2016-10-29
    • 2012-07-09
    • 2012-01-16
    • 2014-01-13
    • 1970-01-01
    • 2013-05-06
    • 1970-01-01
    相关资源
    最近更新 更多