Blocking Bots…

Hi all.

I have noticed some interesting entries in my logs. There were few bots that were visiting me once in a while. I want to block them off ;).

How would one do it? I googled it and found the .htaccess file the easiest way.

Basically You create a file in the main directory of Your website. Lets say for example /var/www/html/ called .htaccess with 644 root permissions.

Then You create a rule.

Deny from env=bad_bot

From now on – everything called bad_bot gets denied. How to mark bot as bad_bot?

BrowserMatchNoCase Morfeus bad_bot

This means: Read the Browser’s user agent and don’t try matching the case. If You find word Morfeus – its a bad_bot.

Voila. This should block them bots and make my server even more secured :).

[root@icsserver ~]# cat ./.htaccess
# http://www.thesitewizard.com/apache/block-bots-with-htaccess.shtml
# hope this will get rid of them b****** ;)!
BrowserMatchNoCase Morfeus bad_bot
BrowserMatchNoCase Strikes bad_bot
BrowserMatchNoCase Again bad_bot
#BrowserMatchNoCase compatible; MSIE 6.0; Windows 98 bad_bot
#BrowserMatchNoCase compatible; MSIE 4.01; Windows 95 bad_bot
BrowserMatchNoCase pozdrawia bad_bot
BrowserMatchNoCase dewelopera bad_bot
BrowserMatchNoCase http://help.goo.ne.jp/door/crawler.html bad_bot
BrowserMatchNoCase ichiro bad_bot
BrowserMatchNoCase Googlebot bad_bot
BrowserMatchNoCase N905i(c100;TB;W24H16) bad_bot
BrowserMatchNoCase Googlebot-Mobile/2.1 bad_bot
BrowserMatchNoCase DoCoMo/2.0 bad_bot
BrowserMatchNoCase http://www.google.com/bot.html bad_bot
BrowserMatchNoCase Yandex bad_bot
BrowserMatchNoCase YandexBot bad_bot
BrowserMatchNoCase http://yandex.com/bots bad_bot
#BrowserMatchNoCase SecurityHoleRobot bad_bot
#BrowserMatchNoCase SecurityHoleRobot bad_bot
#BrowserMatchNoCase SecurityHoleRobot bad_bot
#BrowserMatchNoCase SecurityHoleRobot bad_bot
#Order Deny,Allow
Deny from env=bad_bot
#Deny from 127.0.0.1
[root@icsserver ~]#

# in front of a line means it’s going to be ignored.

And few more details:

[root@icsserver ~]# ls -full ./.htaccess
-rw-r–r– 1 root root 1205 Apr 4 16:02 ./.htaccess
[root@icsserver ~]#

You can block / allow certain countries. You can also block certain IP addy’s / genuine browser agents.

Hope You will find it interesting / helpful.

Andy

AndrzejL

"Never meet Your heroes. Most of the time you'll only end up disappointed." White Polak Male Husband Employee Hetero Carnivorous Fugly Geek @$$hole with ADD Catholic “Some men just want to watch the world burn.”

Comments are closed.