Back to Top

How to Protect file using .htaccess

htaccess protect file

htaccess is a very simple and quick solution for restricting access to files or directory structures.In this post, we will learn about the protecting a file on the server using htaccess file.

Sometimes your web site contains sensitive information which you don’t want to share the public or to allow access others.So you can protect so file using htaccess especially when you don’t want anybody to change the content of the file.

In this article, you protect a file so that when a user visits a page using that directory or file which is not allowed to visitors.

Let’s see the syntax of it which clears the usage of directive in htaccess

SYNTAX:


...

< Files filepath > – It’s a container for directives restricting files match with the specified patterns.

The directive limits the access of the file as per directives in the block to the file which should be a path from documentRoot.

This can be achieved by including following lines of code by adding into the .htaccess file.

# protect file

   order allow,deny
   deny from all

Now, let’s see the code which is used to protect the file for a specific user only. After adding the IP address of the user, it will be accessible to the particular user.

 # protect file
 
   order allow,deny
   deny from all
   allow from 127.0.0.1 // Replace ip address with desire one
 

Above code will enable access for IP address 127.0.0.1 only.That’s it..!! we’re done with the file protection using htaccess file.Let me know if you have any query /issue for implementing this code.

Stay tuned to creativedev… 😉

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

Welcome to Creative Dev

Posted on 7 years ago

Bhumi

How To Repair MySQL Table

Posted on 7 years ago

Bhumi

How to install zend framework on wamp

Posted on 6 years ago

Bhumi

PHP ODBC connection with MySQL

Posted on 7 years ago

Bhumi

Warning: Ignoring WordPress Can Be a Blunder

Posted on 6 years ago

Nick Carter

Hello world

Updated 1 week ago

Nick Carter

In depth Understanding of Laravel Core

Updated 2 months ago

Bhumi

ECMAScript 6 New Features – 2

Updated 1 year ago

Bhumi

The Reader’s Poll – June 2015

Posted on 4 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 4 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 5 years ago

Bhumi