Mini HowTo: using htaccess to block an IP or IP range from accessing your site, or directory

Short Link: https://blog.m3server.com/?p=90

Add the following lines to your .htaccess file in your root directory, or the directory that you wish to protect. Adding to a directory will protect that directory and all directories below it.

Order Allow,Deny
Deny from 123.55.
Deny from 123.45.2.
Deny from 55.123.14.5
Allow from all

Please note, those are example IP addresses, not real ones!

Add this to your .htaccess file, or create one if you do not have one with your favorite text editor, upload the file to the server into the directory you wish to protect.

This will allow any ip to access your site, except those listed. You can add as many as you wish. Note the 2nd example, 123.45.2 – this will block the full class C, from 123.45.2.1 to 123.45.2.254

Again, test it to ensure this is the effect you want. At any time, you can remove the .htaccess file, or rename it to, example, off.htaccess and it will disable any rules you have specified.

Travis