How to Block IP using .htaccess File

September 22, 2023 / How-to Guide

In this guide, we have explained how to block IP using .htaccess file.

Follow the steps-

  1. If you opt to make modifications through .htaccess or wish to establish configurations for a set of addresses, the only requirement is to-
    1. Create .htaccess file in your public_html folder.
    2. Add lines based on your preferences.
  2. To block or let specific IP addresses-
    Use this template to set rules for specific addresses-
    Order Allow,Deny
    Deny from 186.186.186.186
    Allow from all
    In the above example, access to your website from the IP address 186.186.186.186 is restricted, and this IP address will be unable to reach your site.
  3. To block multiple addresses, simply add them on separate lines-
    Order Allow,Deny
    Deny from 186.186.186.186
    Deny from 198.198.198.198
  4. Make a note of one thing, the “Allow from” line is optional if you only wish to deny access, and vice versa.

That is it! You have successfully blocked an IP address using the .htaccess file. Remember to use this method responsibly and only block IP addresses when necessary for security or other legitimate reasons.

Spread the love