Limit Access to Local Area Network Using htaccess

  • Avinash
  • 5
  • Jul 21, 2011
  • Tips & Tricks

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.

# 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
# limit access to local area network only
<Limit GET POST PUT>
 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
</Limit>

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by:

  • http://www.saneeleurope.co.uk webdevelopers

    Code is better to understood.

  • Kris

    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.

    • http://www.xpertdeveloper.com Avinash

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

  • Luke

    Nice that will be useful to keep some docs secured.

    • http://www.xpertdeveloper.com Avinash

      Thanks Luke…