Blocking IP Addresses With .htaccess

What is .htaccess

.htaccess is a file that Apache reads that allows configuration changes on a per-directory basis. One of the handy little tricks one can do with this configuration file is block visitors from viewing a web site.

The Basics – Blocking 1 IP Address

This will refuse all access (GET & POST) to the web site for the IP address 192.168.0.101

The Multiple IP Approach

Blocking IP Ranges

IP’s range from 0 – 255 (ex -192.168.0.0 – 192.168.0.255)
You may also block ranges by way of calculating CIDR (Classless Inter-Domain Routing – pronounced “cider”) IP ranges (8, 16, 24bits)

Get Mean

You can also block host names instead of numeric addresses.

This will block anyone in the Cox.net network. But beware; banning large isp companies such as Cox.net or Comcast.com will block all their users. Do your research when it comes to blocking hostnames. Think about who may be affected.

There are many other ways of blocking IPs, but using .htaccess is one of the more common requests we receive.

share save 171 16 Blocking IP Addresses With .htaccess
1,550 views
Bookmark the permalink.

Comments are closed.