By using WHM/cPanel, server administrators can easily implement configurations on the Apache web server to block malicious bots and prevent them from consuming server resources. In this tutorial, we’ll guide you through the step-by-step process to block bots from Apache via WHM/cPanel. This method ensures that your website remains secure, loads faster, and avoids unnecessary load caused by bad bots.
When managing a website, dealing with unwanted traffic is a constant challenge. Some of the traffic comes from automated bots that may try to scrape your data, spam your forms, or even launch attacks on your site. If your site is hosted on a cPanel server with Apache, it’s crucial to block bots effectively to maintain server performance and security.
Why Should You Block Bots?
While some bots, like search engine crawlers (Googlebot, Bingbot), are beneficial for SEO, others can be harmful. These harmful bots can:
- Consume excessive server resources.
- Slow down website performance.
- Attempt brute force attacks.
- Scrape sensitive data.
- Skew analytics data with fake traffic.
Step-by-Step Guide to Block Bots from Apache via WHM/cPanel
Follow these steps to block bots effectively from your Apache server through WHM:
Step 1: Login to WHM
First, you need to access your Web Host Manager (WHM) with root-level credentials.
- Enter your root username and password to log in.
Step 2: Navigate to Apache Configuration
Once you are in the WHM dashboard:
- In the left sidebar, search for “Apache Configuration.”

- Click on Apache Configuration > Include Editor.

The Include Editor allows you to add custom configurations to the Apache server.
Step 3: Edit the Pre-Main Include Section
- In the Apache Include Editor, find the “Pre-Main Include” section.
- Select your Apache version (usually All Versions is safe).
- Add the following code snippet to block specific bots:

Step 4: Save and Restart Apache
After adding the code, click on Update to save the changes.
<IfModule mod_rewrite.c>
RewriteEngine On
# Block Bad Bots
RewriteCond %{HTTP_USER_AGENT} ^.*(AhrefsBot|SemrushBot|MJ12bot|DotBot|Baiduspider|YandexBot).*$ [NC]
RewriteRule .* - [F,L]
</IfModule>

Then, return to the WHM home screen and restart the Apache server for the changes to take effect:
Navigate to Restart Services > HTTP Server (Apache).
Click Yes to confirm the restart.
Conclusion
Blocking bots from Apache with WHM/cPanel is an essential step to maintaining the security, speed, and reliability of your website. By following the above steps, you can easily block unwanted bots that may harm your server resources or website data.
If you are looking for robust hosting solutions with built-in security, check out our services at Hostrago Hosting.