Disallow certain bots from accessing certain direc

2019-09-05 21:23发布

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

标签: .htaccess
1条回答
何必那么认真
2楼-- · 2019-09-05 22:00

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

查看更多
登录 后发表回答