Allow and Deny IP Addresses From Accessing Your Site Using .htaccess

This is useful for blocking suspicious IP’s or preventing certain regions from accessing your site. It can also be used to allow only a single or a few IP addresses into a secure admin area.

If you don’t already have an .htaccess file for your website you can easily just create a blank file and call it .htaccess in order to move forward.

Here are examples of what you can put in this file:

To Deny a couple IP addresses

order allow,deny
allow from all
deny from 10.20.30.40
deny from 11.22.33.44

You can replace an IP address with an IP address range as well, 10.20. for example would block everything within 10.20.—.— or 10.2 would block 10.2–.—.—

To only allow your IP

order deny,allow
deny from all
allow from 195.21.23.2