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.

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.

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… 😉

Share:
Share on Facebook0

Share on LinkedIn0Tweet about this on TwitterShare on Google+3Buffer this pageDigg thisShare on Reddit0

Leave a Reply

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

Most Popular Posts

Table layout using DIV tags

Posted on 4 years ago

Bhumi

GoTo statement in PHP

Posted on 5 years ago

Bhumi

Mysql String Function FIND_IN_SET( )

Posted on 5 years ago

Bhumi

Post via e-mail in WordPress

Posted on 4 years ago

Bhumi