How To Block IPs via an .htaccess file?

Note that the ‘.’ in front of htaccess makes this a hidden file. You can create a .htaacess file under your public_html folder and  block access to your entire site. To block access to a specific folder, add the .htaccess file within that folder.  For example, to block access to http://domain.com/demo, add the .htaccess file under the public_html/demo folder.

To block IPs, add the following lines in the .htaccess file:

order allow,deny
deny from xxx.x.x.x
deny from xxx.x.x.x
allow from all

This will block IPs xxx.x.x.x and xxx.x.x.x 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 xxx.x.x.x
allow from xxx.x.x.x
deny from all