04-06-2018, 11:21 AM
Objective
Your objective is to password protect some of your Website pages (not all of them).
Method
For this you can use .htaccess in Apache. Principle of how it is done is to create a .htpasswd file and save it in a directory above the public_html directory. Then create a separate directory in your public_html folder. Then create and upload an .htaccess file in the separate directory that will password protect the content of that directory only.
Step 1 - Create and Upload Password File .htpasswd
Create an encrypted user name and password string at the following Website:
http://www.htaccesstools.com/htpasswd-generator/
Then use a text editor to copy and paste the encrypted login and password string and save the file as: .htpasswd
Upload the file one directory up from the public_html directory so it isn't publicly accessible. Make sure it has 644 privileges.
If you want to use more user names and passwords just add them line by line (after you have encrypted them)
Step 2 - Create and Upload .htaccess file
Use your text editor to create a .htaccess file with the following code in it and to save it as a .htaccess file:
AuthUserFile /full/path/to/.htpasswd
AuthType Basic
AuthName "My Secret Page"
<Files "mypage.html">
Require valid-user
</Files>
Be very careful with the section where you provide the path to the password file (first line of code). The full path is the path to the file from the Server's root e.g. /home/username/.htpasswd or C:\wwwroot\username\.htpasswd. Also make sure that the quotes are straight quotes.
Step 3 - Test It
When you access your password protected file, you should be prompted for your login and password
Step 4 - Troubleshooting
Check that the path to your .htpasswd file on the server is correct. In most cases this is where the problem lies. Also make sure that both the .htpasswd and .htaccess files have the correct privileges - chmod 644.
Also check that you uploaded the files to the correct folders.
Your objective is to password protect some of your Website pages (not all of them).
Method
For this you can use .htaccess in Apache. Principle of how it is done is to create a .htpasswd file and save it in a directory above the public_html directory. Then create a separate directory in your public_html folder. Then create and upload an .htaccess file in the separate directory that will password protect the content of that directory only.
Step 1 - Create and Upload Password File .htpasswd
Create an encrypted user name and password string at the following Website:
http://www.htaccesstools.com/htpasswd-generator/
Then use a text editor to copy and paste the encrypted login and password string and save the file as: .htpasswd
Upload the file one directory up from the public_html directory so it isn't publicly accessible. Make sure it has 644 privileges.
If you want to use more user names and passwords just add them line by line (after you have encrypted them)
Step 2 - Create and Upload .htaccess file
Use your text editor to create a .htaccess file with the following code in it and to save it as a .htaccess file:
AuthUserFile /full/path/to/.htpasswd
AuthType Basic
AuthName "My Secret Page"
<Files "mypage.html">
Require valid-user
</Files>
Be very careful with the section where you provide the path to the password file (first line of code). The full path is the path to the file from the Server's root e.g. /home/username/.htpasswd or C:\wwwroot\username\.htpasswd. Also make sure that the quotes are straight quotes.
Step 3 - Test It
When you access your password protected file, you should be prompted for your login and password
Step 4 - Troubleshooting
Check that the path to your .htpasswd file on the server is correct. In most cases this is where the problem lies. Also make sure that both the .htpasswd and .htaccess files have the correct privileges - chmod 644.
Also check that you uploaded the files to the correct folders.