cannot get FilesMatch and mod_rewrite working together

Posted by neil on Stack Overflow See other posts from Stack Overflow or by neil
Published on 2011-01-15T23:49:55Z Indexed on 2011/01/15 23:53 UTC
Read the original article Hit count: 148

Filed under:
|

Hello, I'm having a little difficulty with my .htaccess when combining a password protection on a file and a mod_rewrite:

If I only have this as my .htaccess

<FilesMatch "manage.php">
AuthName "Member Only"
AuthType Basic
AuthUserFile /home/myuser/.htpasswd
require valid-user
</FilesMatch>

It password protects manage.php fine.

If I have this as my .htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|manage\.php|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

It works as expected: robots.txt, index.php and manage.php are left alone and are called as normal, everything else is redirected to index.php/$1

HOWEVER, If I combine them then when I visit manage.php it gets redirected as index.php/$1, i.e. the FilesMatch is causing the entry in rewritecond to be ignored.

If I actually enter a password in the original test and get to the file, it works in this last test. So I guess something is up with the rewrite and the file match.

i.e. entering this causes .\manage.php to be called as .\index.php\manage.php

<FilesMatch "manage.php">
AuthName "Member Only"
AuthType Basic
AuthUserFile /home/myuser/.htpasswd
require valid-user
</FilesMatch>

RewriteEngine on
RewriteCond $1 !^(index\.php|manage\.php|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Thanks for any help :)

© Stack Overflow or respective owner

Related posts about .htaccess

Related posts about mod-rewrite