.htaccess is a configuration file for use on web servers running the Apache Web Server.
In post “Block IP Address on CentOS / Redhat“, it provides one way to block IP address while .htaccess provides a different way to deny visitors by the ip. The visitor blocking facilities offered by the Apache Web Server enable us to deny access to specific visitors, or allow access to specific visitors. This is extremely useful for blocking unwanted visitors, or to only allow the web site owner access to certain sections of the site.
Here is a sample .htaccess file:
deny from 184.108.40.206
deny from 123.45.1.
allow from all
Line “deny from 220.127.116.11″ tells Apache web server to block vistors from IP address 18.104.22.168
Line “deny from 123.45.1.” means any IP address which matches “123.45.1” will be blocked. For example: ‘22.214.171.124’ and ‘126.96.36.199’ would be blocked.
To set-up blocking of all visitors except one IP, .htaccess will looks like
allow from 127.0.15.11
deny from all
The configuration tells the Apache web server to block all visitors except those with the IP address ‘127.0.15.11’