How to block a bot by User Agent Sting

How to block a bot by User Agent Sting

Do you have those bandwidth hogging bots as much as Phil and I do? Did you know you can block them in your .htaccess file?

Block the BOT

Let block the most annoying bot on the internet - Baidu spider

vim .htaccess

Now Add the following to block

RewriteCond %{HTTP_USER_AGENT} Baiduspider [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} Baidu [NC] 
RewriteRule ^.*$ - [F,L]

Thats it save the file, and you are now blocking the Baidu spider

Testing to see if its blocked

One way to do this is to use curl

curl -I http://www.briansnelson.com -A "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"

Now you will get a 403 Forbidden

HTTP/1.1 403 Forbidden
Date: Mon, 06 Jan 2014 19:18:11 GMT
 
 
 
 
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Install Apache Web Server Centos 7

Install Apache Web Server on Centos 7 The Apache HTTP Server Project is an effort to...

MySQL - Check Which Query is Consuming Resources

MySQL - Checking Which Query is Consuming Resources Have you ever wondered which mysql query...

Install Redis on Centos 7 How To

How To install Redis on Centos 7 Redis is an open source, BSD licensed, advanced key-value...

CentOS One Liner Commands

Centos Oneliners kill all pts for x in $(ps aux | grep pts| awk '{print $2}'); do kill...

How to block Bittorent traffic with IPTables

How to Block Bittorrent Traffic with IPtables IPTABLES is a user-space application program...