0

I have created a simple CSM website using core PHP. I have placed my fronted code in root directory i.e. public_html and admin code inside admin directory i.e. public_html/admin.

I want to password protect my admin part with htpassword. Below is my code for admin/.htaccess file.

AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /path/public_html/admin/.htpasswd
ErrorDocument 401 /admin
Require valid-user

I have also added redirect from http to https in root .htaccess file as below

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

htpassword for admin only working if I will remove above code from root .htaccess file.

Anything wrong is there?

Dharman
  • 30,962
  • 25
  • 85
  • 135

2 Answers2

0

Create .htpasswd file in your admin folder.

And then create username and password by using this link : Click Here

Paste the below code in your .htaccess file.

AuthType Basic
AuthName "Restricted Area"
AuthUserFile COMPLETE_PATH_TO_ADMIN_FOLDER/.htpasswd #complete path to .htpasswd file.
require valid-user

I hope it will help you.

dineshkashera
  • 1,442
  • 1
  • 15
  • 26
0

Please make sure that both of your file should be readable to the Web Server i.e .htpasswd and .htaccess use chmod 644 for the trick to work.

Try using my code in your .htaccess file

AuthUserFile /full/path/to/.htpasswd
AuthType Basic
AuthName "My Secret Folder"
Require valid-user

I hope it works :D

Adi.S
  • 280
  • 1
  • 13