Protect file using .htaccess

  • Avinash
  • 1
  • Sep 11, 2011
  • Web Server

This post is about to explain the use of .htaccess for protecting any file on your server.

Earlier I have explained the use of htaccess file to protect the .htaccess file.

Here is the code which shows the trick to protect the file using .htaccess file.

Protect File using .htaccess

# protect file order allow,deny deny from all
 # protect file
 <Files personal_data.txt>
   order allow,deny
   deny from all
 </Files>

Enable access for particular user

# protect file order allow,deny deny from all allow from 1.2.3.4 allow from 45.85.245.105
 # protect file
 <Files personal_data.txt>
   order allow,deny
   deny from all
   allow from 1.2.3.4
   allow from 45.85.245.105
 </Files>

So above code will enable access from 1.2.3.4 and 45.85.245.105 only.

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:

  • killahbeez

    order allow,deny
    deny from all
    allow from 1.2.3.4
    allow from 45.85.245.105

    This will deny all access, not allowing those any of following IPs, because of the order.