In this post we will learn how to easily secure your site’s directory using .htaccess file. Only users with valid credentials can access that directory/site. It’s the quickest and easiest way to protect directories/files in your site with password. It can also be used as a quick way to hide your site when its in maintenance or under construction.
So all you have to do is place the code given below at the end of your .htaccess file.
AuthType Basic AuthName "Please enter username and password to access the page" AuthUserFile C:/wamp/www/infotuts/.htpasswd require valid-user
What Ever you will write as AuthName would be displayed in the popup. AuthUserFile should be the path to directory you want to password protect, it should be particular to your hosting configuration.
Now we have another file called .htpasswd. This file contains the username and password which would be required by user to access the protected page. It should be in a predefined format i.e. username:password
So in our .htpasswd file we have the following credentials:
That’s all. It was quick and easy. We will keep on posting some good htaccess tricks to secure and speed up your website load time. Share this easy tutorial with your friends and followers.