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:
1 2 3 4 5 | <Files file> ... </Files> |
< Files filepath > – It’s a container for directives restricting files match with the specified patterns.
The
This can be achieved by including following lines of code by adding into the .htaccess file.
1 2 3 4 5 6 7 | # protect file <Files filename.txt> order allow,deny deny from all </Files> |
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.
1 2 3 4 5 6 7 8 | # protect file <Files filename.txt> order allow,deny deny from all </Files> |
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… 😉