How to block ips via .htaccess file ?
DATE – 09-05-2020
You can quickly block IP addresses from accessing your sites or specific folders using a .htaccess file. Note that the ‘.’ in front of htaccess makes this a hidden file. Please make sure your have the ‘View Hidden Files’ option checked in your FTP program or through File Manager.
If you do not already have a .htaccess file, you can create or upload a new file and name it ‘.htaccess’. To block access to your entire site, add the .htaccess file under the public_html folder. To block access to a specific folder, add the .htaccess file within that folder. For example, to block access to http://domain.com/dev, add the .htaccess file under the public_html/dev folder.
To block IPs, add the following lines in the .htaccess file:
deny from 222.214.171.124
deny from 126.96.36.199
allow from all
This will block IPs 2188.8.131.52 and 184.108.40.206 from access your files. To add more blocks, simply add more “deny from IP_ADDRESS” lines above the allow from all line.
You may find that you need to block access to a folder for everyone except you, or your developers. To block access for everyone except for specific IPs, add the following to your .htaccess file:
allow from 255.0.0.0
allow from 220.127.116.11
deny from all