Advertisement

Block all bad bots with htaccess in Cpanel

 (Read 900 times)

Admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1549
    • The Jucktion
Block all bad bots with htaccess in Cpanel
« on: Aug 07, 2019, 06:12 PM »
image

There are many bots strolling around the web searching for vulnerabilities or scraping content off websites for many different uses. Most of these bots are useless in terms of providing benefits for the webmasters. They instead take up a lot of bandwidth and resources which could be better used in serving real human visitors. Here's a short htaccess code you can use to block these bad behaving bots.

The first thing to do is find the bad bots visiting to your site. If you have Cpanel, you can do this by viewing the AWStats section which is commonly available on all Cpanel installations. Try checking the month prior to the current one to get a good list of bots visiting your site. Then find the ones you think are useless and should be stopped. You block them on htaccess by creating an environment variable enlisting all the bad bots and then denying them access.

Basically the code looks like this. Here the code matches 'perl' then it is added to a 'bad_bot' variable. Then the last line is used to block the condition matching the 'bad_bot' variable.
Code: [Select]
BrowserMatchNoCase perl bad_bot
Order Deny,Allow
Deny from env=bad_bot

Multiple blocks will look like:
Code: [Select]
#BrowserMatchNoCase perl bad_bot
#BrowserMatchNoCase crawl bad_bot
#BrowserMatchNoCase robot bad_bot
#BrowserMatchNoCase nbot bad_bot
#Order Deny,Allow
#Deny from env=bad_bot

Save the file and the htaccess is put to work. It will now block the user-agents matching the bad bot list and prevent them from accessing your website's content.

Advertisement

Best Affiliate Program