How to Block Or Deny visitors IP Address by .htaccess

Here we will learn different ways to block visitors via their IP address. This is extremely useful for blocking unwanted visitors, or to only allow the web site owner access to admin panel.

Block a specific IP address

To block special IP addresses, you need to insert the following code in a .htaccess file located in your directory.

order allow,deny
deny from 1.2.3.4
allow from all

Block multiple IP addresses

To block multiple IP addresses, you need to insert the following code in a .htaccess file located in your directory.

order allow,deny
deny from 255.0.0.0
deny from 123.45.6.
allow from all

Block entire subnet

To block every IP that begins with 123.123, you need to insert the following code in a .htaccess file located in your directory.

order allow,deny
Deny from 123.123
allow from all

Block all Ip except your Ip Address

To block every IP except your ip address, you need to insert the following code in a .htaccess file located in your directory.

order allow,deny
allow from 255.0.0.0
deny from all