【发布时间】: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 重定向到索引
【问题讨论】: