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

Leave a Reply

Your email address will not be published.

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

Most Popular Posts

How to add ColorDots in FullCalender?

Posted on 9 years ago

Bhumi

PHP Tutorial for beginners

Posted on 7 years ago

Bhumi

What Are WordPress Nonces?

Posted on 8 years ago

Bhumi