Thursday, May 2, 2013

Deny/Allow Certain IP Addresses with htaccess

If you have problems with certain visitors to your website, you can easily ban them. There are two different ways to ban visitors. This can be done using their IP address or with the domain name which they came from. Here's an example showing you how to deny a user by their IP address:
order allow,deny
deny from 201.68.101.5
allow from all
The above code will deny the 201.68.101.5 IP address and allow everyone else to enter. If you want to deny a block of IP addresses, use this code:
order allow,deny
deny from 201.68.101.
allow from all
The above code will deny the 201.68.101.0 IP address, the 201.68.101.5 IP address and all the way up to 201.68.101.255 or 255 IP addresses. Here's an example showing you how to deny a user by the domain name from which they came from:
order allow,deny
deny from www.theirdomain.com
allow from all
The above code will deny anyone coming from www.theirdomain.com and allow everyone else to enter. Here's an example showing you how to deny a user from a domain name and all subdomains within the domain name:
order allow,deny
deny from .theirdomain.com
allow from all
The above code will deny anyone coming from www.theirdomain.com, all sub-domains within the domain and allow everyone else to enter.
order deny,allow
deny from all
allow from YOUR_IP_ADDRESS
The above code will block all visitors from accessing your site except for yourself if you replace youripaddress with the IP address that was assigned to you by your ISP.
Disqus Comments