3

The root folder of a web app is protected with a .htaccess/.htpasswd file. That works fine even with sub-folders, and everything is perfect.

Now I have to password protect a subfolder using a different .htpasswd file. I tried using a new .htaccess/.htpasswd combo into the subfolder and it kinda works, except for the fact that I need to enter two usernames and passwords (one for the subfolder and one for the .htaccess/.htpasswd in the root folder).

Is there a way to avoid that?

Thanks

4

1 回答 1

3

没有直接的方法可以做到这一点。我的解决方案是明确定义需要有效用户的目录(使用根 .htpasswd),并排除具有自己身份验证的目录。前任:

.htaccess (root)
AuthUserFile /full/path/to/.htpasswd
AuthType Basic
AuthName "My Secret Page"

<Directory "/var">
  Require valid-user
</Directory>

<Directory "/etc">
  Require valid-user
</Directory>

在子文件夹 ex "/users" 中,您将放置自定义 .htaccess 和 .htpasswd 来管理身份验证。

当然,请始终检查您在 .htpasswd 中的用户条目是否受操作系统支持。

于 2012-11-02T14:30:49.657 回答