У меня есть директива filesmatch в моем файле .htaccess:
<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 от большей части веб-сайта, не знаю, конфликтует ли это).
Правило перезаписи мода:
<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>
FilesMatch соответствует объекты физической файловой системы. index.php / admin к их числу не относится.