Question

I am trying to protect an index.php page of a subfolder with .htaccess.

The protection works as expected when I navigate to example.com/subfolder/index.php. However, when I just go to example.com/subfolder I get a 401 error.

Here is the relevant .htacess code:

AuthUserFile /home/myfolder/subfolder/.htpasswd

AuthName "Please enter your password"

AuthType Basic

<files index.php>
  require valid-user
</files>

What do I need to do differently?

Était-ce utile?

La solution

You should put a new .htaccess file in the subfolder directory with just the following in it:

AuthUserFile /home/myfolder/subfolder/.htpasswd
AuthName "Please enter your password"
AuthType Basic

require valid-user

That will password protect the entire directory

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top