Deny IPs or exclude URLs using .htaccess

There are several reasons to deny specific IP addresses or exclude URLs from your website. For example a traffic intensive Spider  or to reduces grant access to an specific intranet host only. Just to point it out – I use the Adress 127.0.0.1 in this post for practice examples.

Lock out a specific IP address

order allow,deny
allow from all
deny from 127.0.0.1

The IP address obtained when the page is called a 403 (Not Authorized). All other access

Lock out multiple IP addresses

order allow,deny
allow from all
deny from 127.0.0.1
deny from 127.0.0.2
deny from 127.0.0.3

Just write ip addresses to be blocked  to the fileline by line

To Lock out a range of IPs

order allow,deny
allow from all
deny from 127.0.0

All addresses correspond to this IP range excluded. In this case 127.0.0.1 to 127.0.0.255

Allow only specific IP addresses

order allow,deny
deny from all
allow from 127.0.0.1

As described in the Examples all settings work with “allow from” like it does with “deny from“.

Stay tuned!

Leave a Comment