.htaccess deny access multiple files

.htaccessapache-2.4

I would like to deny access to multiple files with exactly name. So I tried with no success:

<Files config.inc.php config_smtp.inc.php>
  Order allow,deny
  Deny from all
</Files>

I cannot use FilesMatch because I want to deny files with exactly name.

Best Answer

I cannot use FilesMatch because I want to deny files with exactly name.

FilesMatch is precisely what you can use. For example:

<FilesMatch "^(config\.inc\.php|config_smtp\.inc\.php)$">
  Order allow,deny
  Deny from all
</FilesMatch>

In this case the regex could be shortened a bit, eg. ^config(_smtp)?\.inc\.php$ to match the same two files as above.

Note that since you're on Apache 2.4, you should be using mod_authz_host instead. For example:

<FilesMatch "^(config\.inc\.php|config_smtp\.inc\.php)$">
  Require all denied
</FilesMatch>
Related Topic