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 255.0.0.0
deny from 18.104.22.168
allow from all
This will block IPs 255.0.0.0 and 22.214.171.124 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 126.96.36.199
deny from all