Ruf1
Ruf1

Reputation: 179

How can I block a Bot with .htaccess

Im having problems with bot* and *bot. I have limited knowledge of .htaccess but have been blocking bots with .htaccess rules below.

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*

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]

Upvotes: 0

Views: 805

Answers (2)

anubhava
anubhava

Reputation: 785068

You can combine all those conditions into one as:

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

NC is for ignore case.

Upvotes: 0

Nirjhor Anjum
Nirjhor Anjum

Reputation: 1

RewriteEngine On 
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR] 
RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:[email protected] [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:

Order Deny,Allow
Deny from 127.0.0.1

Upvotes: 0

Related Questions