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

Short Link:

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
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 to

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.