0

I need to block certain bots from accessing certain directories on my website. This is almost identical to this question except that I don't want to create different .htaccess file in each folder I want to block. I need to use the root .htaccess file.

Regex has been giving me a hard time really. Appreciate your help

Community
  • 1
  • 1
Ahmad Alfy
  • 13,107
  • 6
  • 65
  • 99

1 Answers1

2

Just create a list of folders and add the same condition before each one:

RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot|Baiduspider) [NC]
RewriteRule ^folder1/ - [L,F]

RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot|Baiduspider) [NC]
RewriteRule ^folder2/anotherfolder/ - [L,F]

RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot|Baiduspider) [NC]
RewriteRule ^folder3/path/to/disallowedfolder/ - [L,F]

etc..

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • 1
    @AhmadAlfy You can use either, the `F` flag returns a 403 forbidden sam as `R=403`, and is the documented way to do it. – Jon Lin Aug 06 '13 at 09:29