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