How to block ips via .htaccess file ?
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:
order allow,deny
deny from 290.0.0.0
deny from 111.111.1.1
allow from all
This will block IPs 290.0.0.0 and 111.111.1.1 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:
order allow,deny
allow from 255.0.0.0
allow from 2.2.2.2
deny from all
Thank you.