If you wanted a specific directory in your site to be available only to a specific people or if your site is in staging mode, so you can use password protecting method to your site which can be possible by htpasswd file.
The password file is used to store valid username and password information which require accessing site/directory. Basically, Apache provides a program to create a password file and the program called htpasswd which is automatically installed in bin which is the subdirectory of the apache like
Steps to Create Htpasswd file
Below are the steps to create htpasswd file
Step 1: Create .htpasswd file
First of all, you need to create a file called .htpasswd and place the username and password (encrypted) into your .htpasswd file.
Username is admin and password are 123456 so the htpasswd file would be like
Here, UserName comes first followed by the Password and password must be in encrypted form.Now, upload .htpasswd file into a root directory.
You can generate encrypted password from here
Step 2: Create .htaccess file
Create a new .htaccess file and place the following code
AuthName "Restricted Area" AuthType Basic AuthUserFile /home/site/.htpasswd AuthGroupFile /dev/null require valid-user
Next, upload .htaccess file and test your URL by accessing it.
The AuthName is the name of the area you want to access.AuthType Basic is because we are using basic HTTP authentication.AuthUserFile is the root path of the server to the htpasswd file.require valid-user means the only valid user can access the directory from the entire list of users.
NOTE:Above code will only work on Web servers which support Htaccess. If you don’t have an idea that your server supports Htaccess, you should contact your hosting provider.