In this guide, we have explained how to block IP using .htaccess file.
Follow the steps-
- If you opt to make modifications through .htaccess or wish to establish configurations for a set of addresses, the only requirement is to-
- Create .htaccess file in your public_html folder.
- Add lines based on your preferences.
- 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. - 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 - 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.