0

I have multiple folders on my website and one .htaccess in the root of the site. I want to deny access to some of them using htaccess. I found this post:

Deny access to one specific folder in .htaccess

Its solution is creating .htaccess file in target folder but I want to do this work using one .htaccess. I want to deny access to target folders using one .htaccess in the root of the site.

Is it possible?

Omid Nikrah
  • 2,307
  • 3
  • 12
  • 27
Mohammad
  • 20,339
  • 15
  • 51
  • 79

2 Answers2

2

If you want to deny access to subfolders from root lavel htaccess, you can use the following RewriteRules :

RewriteRule ^folderA/$ - [R=403,L]
RewriteRule ^folderB/$ - [R=403,L]

The rules will return a 403 forbidden error if /folderA/ and /folderB is requested.

Amit Verma
  • 39,545
  • 18
  • 87
  • 107
0

You can try:

RewriteEngine On
RewriteRule ^folder1/ - [F]
RewriteRule ^someotherfolder/ - [F]
# you can also use RegEx:
RewriteRule ^folder([0-9]+)/ - [F]
Dusan Bajic
  • 9,499
  • 3
  • 34
  • 39