Can I write multiple statements in one htaccess?
Yes you can. Many
containers in the same the context (that is to say.
.htaccess) are merged in order. So you can block everything
.php files and allow a specific
foobar.php file – in that order.
# Block all ".php" files
Order deny,allow Deny from all# Permit a specific ".php" file Order deny,allow Allow from all
Alternatively, you can use only one
container and use a negative look in the regex to exclude the specific file:
# OR use a negative lookahead...
Order deny,allow Deny from all
the negative affirmation of anticipation
(?!foobar.php$) ensures that the regex does not match
foobar.php, while corresponding to all others
Allow are strictly Apache 2.2 directives. If you are using Apache 2.4, then you should probably change this to
Require all denied and
Require all granted respectively (provided you have switched to mod_authz_core on your system).
Also note that the
container is applied to the current directory and all subdirectories.