Knowledge Base
MilesWeb / cPanel

Steps to Enable Password Protection for .htaccess?

Approx. read time : 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.

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.
Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.