Ahmad Alfy
Ahmad Alfy

Reputation: 13371

Disallow certain bots from accessing certain directory using htaccess

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

Upvotes: 0

Views: 887

Answers (1)

Jon Lin
Jon Lin

Reputation: 143876

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..

Upvotes: 2

Related Questions