If you want to know how to enable .htaccess password protection, you can do it in a couple of steps.

Here’s how to accomplish this task –

Step 1

Create .htpasswd file with your desired username and password in any text editor (like Notepad) and save without the .txt extension. It is a good idea to encrypt the password for extra protection.  As you visit the link, simply enter the username and password and it will generate the code for you, which you can copy and paste. For a user ‘abc’ and password ‘abc’, I got this (but it generates a new one everytime) – abc:9476nIHW7Esgw

Step 2

Create .htaccess file with the code below. It can be created using any text editor (like Notepad) and saved without the .txt extension. Remember to double check the location of the htpasswd file, or it will not work. You can change ‘Login Details’ to whatever you want displayed on the pop up alert.

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

Step 3

Upload both these files in the same folder which you want protected (in this case ‘secretfolder’). Now whenever anyone accesses that directory or any files in it, they will be asked for login details. You web directory is now password-protected.

[**NOTE – You might not be able to see these files on your server since they are hidden files. I use Filezilla FTP client and often use the “force showing hidden files” option to view these files. Also remember that these files can be created easily in Notepad but save without .txt extension (Save a type – choose “All Files”, then you can save without any extension). If the Login window keeps popping up, most probably your login details are wrong.]


Leave a Reply

Your email address will not be published.