0

I have an htaccess file in my root directory to add rules such as force www on website, etc.

I want to protect a directory on my site such as example.com/private/ and example.com/private/p/

I here is where my htaccess files are:

/public_html/.htaccess (htaccess file to force www. on my site)
/public_html/private/.htaccess (protect directory code)
/public_html/private/.htpasswd (usernames and passwords for directory)

I keep getting a 401 Unauthorized when i try to click on a link to a /private/ URL and don't even get the password prompt sometimes. I have tried clearing my cache, but it still does not work.

Here is my /private/.htaccess code (protect directory code) (I know my AuthUserFile path is right by the way):

AuthType Basic
AuthName "Members Only"
AuthUserFile /public_html/private/.htpasswd
<limit GET PUT POST>
require valid-user
</limit>

When I remove the /public_html/.htaccess file, the login works fine. Anyone know why and how to fix this so I can use both .htaccess files?

Anthony4
  • 92
  • 6

1 Answers1

0

Try change path to .htpasswd (in line "AuthUserFile /public_html/private/.htpasswd") to full path of your file. Example /home/username/www/public_html/private/.htpasswd

JarekBaran
  • 1,311
  • 2
  • 7
  • 12
  • Yes, i'm sure the AuthUserFile is correct. It has been `AuthUserFile /storage/ssd4/782/3883334/public_html/private/.htpasswd` and it works perfectly fine. It seems to be a problem with ssl that I am not getting the prompt. When I turn off https through cloudflare, it seems to work fine and I get the popup like normal. Any idea why it doesn't work with https? – Anthony4 Apr 28 '19 at 18:03