I want the content of a directory "dir" protected, but if the user accesses the directory itself, I want a PHP file from the parent directory served instead. This works with the following configuration:
<VirtualHost *:80> LogLevel debug DocumentRoot "/var/www/html" ServerName example.com <Directory /var/www/html> SetEnvIf Request_URI "dir/$" allow Order allow,deny Allow from env=allow Satisfy any RewriteEngine on RewriteRule dir index.php?id=dir [QSA,L] </Directory> <Directory /var/www/html/dir> Require user valid-user AuthName "Restricted" AuthType Basic AuthUserFile /etc/apache2/.htpasswd #RewriteEngine on </Directory> </VirtualHost>  When I access "example.com/dir" the content of index.php is displayed, when I access "example.com/dir/file.html" I have to authenticate first. Everything is as wanted.
But when I now try to create RewriteRules for other files, I quits working. When I just uncomment the line "#RewriteEngine on" at the end, I get a 404 not found when I try to access "example.com/dir".
Why does this happen? I don't need other rewrite rules for "dir" itself but for some files within the directory.