Securing directory with .htaccess
Last Modified at 2019-06-25 21:29:26
Protecting files of your website is very important. To do this, either you will have to create login form and add the form in every page or you can do the same with .htaccess with little bit of codes.
The advantage of securing directory with htaccess are:
- Your protected directory and your directory and its files will not be indexed by search engines
- Your files, images etc will not be displayed before sucessfull authentication
- Minimal code than creating login form
- You can also be able to protect your wordpress website wp-admin folder etc
To make this happen, you need two files 1).htaccess and 2) .httpaswd
Add below code in the .htaccess file.
AuthName "This folder requires authentication"
About AuthType, AuthName, AuthUserFile and requireAuthType:
It tells apache to what types of authentication to use.AuthName:
It tells what will be displayed on the password prompt.AuthUserFile:
authentication user file location.require:
Require tells Apache which authenticated users will be granted access to a resource.
And now add the below code in .httpasswd file
The .httpasswd file contains login information of allowed users. you can add multiple users by one per line. You can encrypt your password with lot of free .htaccess password encryption tools on the internet.
Hope this tutorial help you . Please share your opinion. Thank you.