![htaccess 中的 Apache“filesmatch”指令与预期不匹配](https://linux22.com/image/589134/htaccess%20%E4%B8%AD%E7%9A%84%20Apache%E2%80%9Cfilesmatch%E2%80%9D%E6%8C%87%E4%BB%A4%E4%B8%8E%E9%A2%84%E6%9C%9F%E4%B8%8D%E5%8C%B9%E9%85%8D.png)
我的 .htaccess 文件中有一个 filesmatch 指令:
<filesMatch "admin">
AuthUserFile /var/www/html/.htpasswd
AuthType Basic
AuthName "Protected Area"
require valid-user
</filesMatch>
它匹配http://www.website.com/admin(以及子页面,例如 /admin/edit_page)
但不是http://www.website.com/index.php/admin
(我还有一个 mod_rewrite 规则来隐藏大多数网站的 index.php,不知道这是否会冲突)。
mod重写规则:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
答案1
FilesMatch 匹配物理文件系统对象.index.php/admin 不是其中之一。