Controlling access to your website by IP address using .htaccess

Blocking or allowing IP addresses to your website using .htaccess is very easy. You can block a specific IP address or range, or you can block all traffic and allow only a specific IP address or range, the choice is yours. Create a file called


and add three lines to it using the examples below.

To block a specific IP:

order allow,deny
deny from
allow from all

To allow only a specific IP:

Order allow,deny
deny from all
allow from

Make sure that the .htaccess file permissions are secure, you’ll probably want to set it’s permissions to 644 (RW-R–R–).