Deny visitors by IP address using Apache .htaccess file

.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:

order allow,deny
deny from 104.193.9.233
deny from 123.45.1.
allow from all

Line “deny from 104.193.9.233″ tells Apache web server to block vistors from IP address 104.193.9.233
Line “deny from 123.45.1.” means any IP address which matches “123.45.1” will be blocked. For example: ‘123.45.1.20’ and ‘123.45.1.21’ would be blocked.

To set-up blocking of all visitors except one IP, .htaccess will looks like

order allow,deny
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’

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditShare on StumbleUponEmail this to someoneShare on TumblrDigg this

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">