If you have an offender, always abusing your server or dumping spam through your contact forms… the tutorial below will teach you how to block them from accessing your website. It should be noted, however, that this post is specific to Linux servers with HTACCESS functionality.

Block Bots

The below instructions look for robots that begin with a name of “BadBot” and tells it to go to http://take.a.hike/ which translates to a long walk off a short pier. Adjust accordingly.

   #get rid of the bad bot
   RewriteEngine on
   RewriteCond %{HTTP_USER_AGENT} ^BadBot
   RewriteRule ^(.*)$ http://take.a.hike/

Block Leechers (Hotlinkers)

Steeling bandwidth and server resources can cripple your site and ultimately your repeat traffic. No one likes a slow site. To prevent other website from hot linking or leeching your content, use the code below:

   #### BAD SITE REDIRECT ####
   RewriteEngine on
   RewriteCond %{HTTP_REFERER} badwebsite.com [NC]
   RewriteRule .* - [F] 

   #### BLOCK MORE THAN ONE SITE ####
   RewriteEngine on
   RewriteCond %{HTTP_REFERER} ^http://.*badwebsite.com [NC,OR]
   RewriteCond %{HTTP_REFERER} ^http://.*secondbadsite.com [NC,OR]
   RewriteCond %{HTTP_REFERER} ^http://.*thirdbadsite.com [NC]
   RewriteRule .* - [F] 

The code above will return a 403 Forbidden error to anyone trying to hotlink your images on badwebsite.com. The end result: users on that site will see a broken image, and your bandwidth is no longer being stolen.

Block by IP

My personal favorite… block a person from accessing your website by their IP.

    #### BLOCK BY IP ####
    order allow,deny
    deny from 192.168.44.201
    deny from 224.39.163.12
    deny from 172.16.7.92
    allow from all

All of the examples above are specific to HTACCESS. If you are on a Windows Server, this will not work for you. Happy blocking!