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,444
  • 3
  • 15
  • 30
Mohammad
  • 21,175
  • 15
  • 55
  • 84

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
  • 40,709
  • 21
  • 93
  • 115
1

You can try:

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