Search Keyword:

23Jun

IP address restrictions to protect directories using .htaccess

Posted by admin as Others

web-folder-restrict

This is a simple quick tool to protect any given directory of your choice by limiting the users viewing and accessing the folder by specifying the IP addresses that can only access it in .htaccess

1. Open your text editor, copy and paste the following code:


AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "Example Access Control"
AuthType Basic
<LIMIT GET>
order deny,allow
deny from all
allow from 192.168.0.0
allow from 123.4.56.78
allow from 125.5.68.72
allow from 125.5.68.73
allow from 202.138.133.242
</LIMIT>


2. Replace the “allow from” lines to IP addresses that can access the folder/directory. These lines can only be one or can be many as you need.

3. Save the file as .htaccess

4. Upload to the root of the directory that you are trying to protect.

  • Digg
  • del.icio.us
  • Tumblr
  • StumbleUpon
  • Technorati
  • Reddit
  • NewsVine
  • Slashdot
  • DZone
  • Facebook
  • Twitter

1 Response to IP address restrictions to protect directories using .htaccess

Lucifer Dreams

July 24th, 2011 at 3:38 am

Would you also want to protect the htaccess file with the following?

order allow,deny
deny from all

Or some included form with what you have above. Thanks also for the info.

Comment Form

Sponsored Links



Recent Comments

  • Alex13: Hi! thanks for this great post and code. I found a problem with it and need your help: I have in my form an...
  • Krishnakiran: Do anyone have a sample code for this
  • Paul: Nice, that is exactly what I was looking for, thanks!
  • Czek: can i use this with php uploads? my server does not support APC or Pecl upload progress..i need to provide user...
  • anup: thanx it helped me alot…