To block a specific IP address using Apache's .htaccess file, follow these steps:
Open the .htaccess File: Locate your .htaccess file in your web server's root directory.
Block a Single IP Address:
<RequireAll>
Require all granted
Require not ip X.X.X.X
</RequireAll>
X.X.X.X with the actual IP address you wish to block.Allow Access for a Specific IP Address:
<RequireAll>
Require all denied
Require ip X.X.X.X
</RequireAll>
X.X.X.X with the IP you want to allow.Country-wide Blocking:
.htaccess file.Apply Changes: After making modifications, restart your Apache server to ensure the changes take effect.
Example Configuration:
To block 192.168.1.1, add:
<RequireAll>
Require all granted
Require not ip 192.168.1.1
</RequireAll>
To allow only 192.168.2.3:
<RequireAll>
Require all denied
Require ip 192.168.2.3
</RequireAll>