Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  cPanel  >  Steps to Enable Password Protection for .htaccess?
Top Scroll

Steps to Enable Password Protection for .htaccess?

 3 min

The article reveals the steps to enable .htaccess password protection.

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

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

3. Next, create an .htaccess file with the below code. You can use any text editor save it without the .txt extension. Don’t miss to check the .htpasswd file’s location or else it won’t work.

4. It is possible to change the ‘Login Details’ to anything you want 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 in the same folder which you want to be secure. Now, if any other user than you tries to access that directory or any files in it, they will be asked for login details. So, your web directory is now secured with the password.

NOTE – You won’t be able to see these files on your server as they are hidden files. You can view the Filezilla FTP client and check the “force showing hidden files” option to view these files. You can also create these files easily in Notepad but save them without .txt extension (Save a type – select “All Files”, then you can save without any extension). In case the Login window keeps popping up, it indicates that your login details are wrong.
That’s it! You have now learned to enable password protection for .htaccess.
For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
Claim the discount before it’s too late. Use the coupon code:
Note: Copy the coupon code and apply it on checkout.