子文件夹.htacess不覆盖父.htacess选项

时间:2019-01-31 22:43:34

标签: apache .htaccess redirect

我在域的根目录上有一个.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

我试图将.htaccess放在/ admin /中,如下所示:

<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重定向到索引

1 个答案:

答案 0 :(得分:0)

找到问题/解决方案。

需要添加到/ admin /

中的.htaccess中
 <Files *>
    Order Allow,Deny
    Allow from all
</Files>