.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 220.127.116.11
deny from 123.45.1.
allow from all
Line “deny from 18.104.22.168″ tells Apache web server to block vistors from IP address 22.214.171.124
Line “deny from 123.45.1.” means any IP address which matches “123.45.1” will be blocked. For example: ‘126.96.36.199’ and ‘188.8.131.52’ 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’