To enhance the security of your website hosted on an Apache server through WHM/cPanel, blocking bots is a crucial step. This guide will walk you through the process of setting up rules in .htaccess to block unwanted bots. By following these steps, you can protect your site from malicious traffic and improve performance.

  1. Start by logging into your cPanel account. Use your web browser to navigate to your cPanel login page and enter your credentials.
  2. Once logged in, find the "Files" section on the main dashboard. Click on the "File Manager" icon to open it. Ensure you have selected the correct document root directory for your website (usually public_html).
  3. In the File Manager, locate the .htaccess file in your website's root directory. If it does not exist, create a new file named ".htaccess". Right-click on the file and select "Edit" to open it for modification.
  4. To block bots, you will need to add specific rules to the .htaccess file. Start by adding the following lines at the top of your .htaccess file:
    SetEnvIfNoCase User-Agent ^[Ww]eb[Bb]ot GoAway
    SetEnvIfNoCase User-Agent ^[Ss]lurp GoAway
    SetEnvIfNoCase User-Agent ^[Ll]ib[Ww]eb[Ss]ucker GoAway
    Deny from env=GoAway

    These lines identify and block common bots by checking the User-Agent string.
  5. For more granular control, you can add rules to block specific IP addresses or ranges. For example, to block a single IP address (e.g., 123.45.67.89), add:
    Deny from 123.45.67.89

    To block an entire range of IPs (e.g., 123.45.0.0/16), use CIDR notation:
    Deny from 123.45.0.0/16
  6. After adding your rules, save the changes to the .htaccess file by clicking the "Save" button in the File Manager.
  7. To verify that your bot blocking rules are working, you can use online tools or services that simulate a web request with a specific User-Agent string. Check if these requests are being blocked as expected.

By following this walkthrough, you should now have successfully configured your Apache server through WHM/cPanel to block unwanted bots. This setup helps in reducing the load on your server and enhances security by preventing access from malicious bots.