Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deny access to multiple files in htaccess

I'd like to deny multiple files through htaccess.

<FilesMatch (profile|reg|register|..............|)\.php>
order allow,deny
deny from all
</FilesMatch>

I have lots of files (6 folders with like 30 files each) that I want to deny access to, so using the method above by entering them one by one will take time.

Could I deny access to all files in the folders like this?

<Directory /www/php/login/pages>
  Order Allow,Deny
</Directory>
like image 748
Kilise Avatar asked Jan 16 '23 10:01

Kilise


1 Answers

To multiple

<FilesMatch "(foo|bar|doo)\.php$">
    Deny from all
</FilesMatch>

or go for rewrite rules (RewriteEngine On)

RewriteRule \.(psd|log)$ - [NC,F]

To deny access to all files in the folders:

rewriteRule ^www/php/login/pages - [NC,F]

or simply place a `Deny from all' directly in that folder...

Update 2015: Using Apache 2.4 or higher, the `Deny from all' would needs adjustment.

like image 137
Frank Nocke Avatar answered Jan 25 '23 15:01

Frank Nocke