简体   繁体   English

如何使用.htaccess阻止Bot

[英]How can I block a Bot with .htaccess

Im having problems with bot* and *bot. 我在bot *和* bot方面遇到问题。 I have limited knowledge of .htaccess but have been blocking bots with .htaccess rules below. 我对.htaccess的了解有限,但是一直在使用以下.htaccess规则阻止漫游器。

My question is in 2 parts: 我的问题分为两个部分:

  1. Is my approach correct and if not how do I improve it, and 我的方法正确吗?如果不正确,如何改进?
  2. what is the correct syntaxt to block * bot and bot * 什么是阻止* bot和bot *的正确语法?

Many thanks in advance 提前谢谢了

#Enable RewriteEngine
RewriteEngine On

# Stop the Nasties!!
RewriteBase /


RewriteCond %{HTTP_USER_AGENT} ^autoemailspider [OR]
RewriteCond %{HTTP_USER_AGENT}  baiduspider [NC,OR]
RewriteCond %{HTTP_USER_AGENT}  baidu [NC,OR]
RewriteCond %{HTTP_USER_AGENT}  Baiduspider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Baiduspider* [OR]

RewriteRule ^.* - [F,L]
RewriteEngine On 
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR] 
RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR] 
RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon [OR] 
RewriteCond %{HTTP_USER_AGENT} ^Zeus 
RewriteRule ^.* - [F,L]

Yes, it is right way... 是的,这是正确的方法...

And, if you want to block any IP, then as an example: 并且,如果您要阻止任何IP,请以以下示例为例:

Order Deny,Allow
Deny from 127.0.0.1

You can combine all those conditions into one as: 您可以将所有这些条件合并为:

RewriteCond %{HTTP_USER_AGENT} (autoemailspider|baidu) [NC]
RewriteRule ^ - [F]

NC is for ignore case. NC是忽略情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM