Steps to Enable Password Protection for .htaccess?

In this tutorial will understand the steps to enable .htaccess password protection.

1. Firstly, create an .htpasswd file together with your own username and password in any text editor and save it without the .txt extension. Encrypt the password for further protection.

2. When visiting the link, simply enter the username and password. This may generate the code for you that you just need to copy and paste. During this example, the username was ‘abc’ and password too was ‘abc’ so the result was – abc:9476nIHW7Esgw. However it generates a new one each time.

3. Next, create an .htaccess file using the code as below. Using any text editor you can save the file without the .txt extension. Also check the .htpasswd file’s location without fail or else it won’t work.

4. It is possible to change the ‘Login Details’ to anything you wish to be displayed on the pop-up alert.

AuthUserFile /home/user/domain/secretfolder/.htpasswd
AuthType Basic
AuthName “Login Details”
Require valid-user

5. Both these files need to be uploaded within the same folder that you wish to be secure. Now, if the other user than you tries to access that directory or any files in it, they’ll be asked for login details. So, your web directory is currently secured with the password.

NOTE – You won’t be able to see these files on your server as they’re hidden files. you’ll read the Filezilla FTP client and check the “force showing hidden files” choice to read these files. you’ll also create these files simply in Notepad but save them without .txt extension (Save a type– choose “All Files”, then you’ll save without any extension). Just in case the Login window keeps popping up, it indicates that your login details are wrong.

That’s it! You can enable password protection for .htaccess using the above given steps.