1. Home
  2. Tips and Tricks
  3. How to Block Access to a Site using .htaccess with a Specific IP

How to Block Access to a Site using .htaccess with a Specific IP

To block access to a specific IP address using .htaccess in Apache, you can use the following directives. Open or create an .htaccess file in the root directory of your website, and add the following lines:

<Files "*">
    Order Deny,Allow
    Deny from 123.456.789.012
</Files>

Replace 123.456.789.012 with the actual IP address you want to block.

If you want to block multiple IP addresses, you can add additional Deny from lines:

<Files "*">
    Order Deny,Allow
    Deny from 123.456.789.012
    Deny from 987.654.321.012
</Files>

Alternatively, you can use CIDR notation to block a range of IP addresses:

<Files "*">
    Order Deny,Allow
    Deny from 192.168.1.0/24
</Files>

This example blocks all IP addresses in the range 192.168.1.0 to 192.168.1.255.


Make sure to replace the examples with the actual IP addresses or ranges you want to block. Additionally, note that this method is effective for basic blocking, but more advanced security measures might be needed in some cases. Always test thoroughly to ensure that your configurations work as intended.

Updated on December 27, 2023
Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Email: support@noc.org