Tips & Tricks

Limit Access to Local Area Network Using htaccess

unauothorized access using htaccess

Recently I have posted several articles describing the use of the .htaccess file.

In this post I will explain how can we limit the access of the website to Local Area Network only.

You can specify the IP range for which you want to allow the access.

You need to place the below code in .htaccess file.

[cc lang=”apache”]
# limit access to local area network only

order deny,allow
deny from all
allow from 192.168.0.0/111
# This will limit the access only from 192.168.0.0 to 192.168.0.111

[/cc]

Shares:
  • webdevelopers
    July 21, 2011 at 3:54 pm

    Code is better to understood.

    Reply
  • Kris
    Kris
    July 21, 2011 at 9:54 pm

    How do the rules work – when it says deny from all, does it not match all requests including 192… Given my background in ASP.NET, I am curious how it works as the rules are exactly the opposite in ASP.NET. Also is it possible to use NTLM based authentication with Apache in a Windows environment.

    Reply
    • Avinash
      July 28, 2011 at 7:27 am

      Yes first we have declared that “deny from all” and then after we have also declared the “allow from 192.168.0.0/111”,

      How to assign permission is based on this sentence “order deny,allow”.

      Reply
  • Luke
    Luke
    July 28, 2011 at 12:59 am

    Nice that will be useful to keep some docs secured.

    Reply

Leave a Reply

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