htaccess用户具有不同的权限
我正在尝试使用 htacess 实现以下目标:
** adminuser **
/dir <= has access to directory listing or parent dir
/dir/subdir-n <= has access to directory listing of any sub-dir
** clientuser **
/dir <= DOES NOT have access to directory listing or parent dir (preferably Directory Index that points to a blank index.html file)
/dir/subdir-n <= has access to directory listing of any sub-dir
基本上,我们希望我们的管理员能够通过管理员登录查看所有子目录列表,而我们的个人客户端只能查看他们的目录,我们将与他们通信,但都使用相同的登录名。
I am trying a achieve the following with htacess :
** adminuser **
/dir <= has access to directory listing or parent dir
/dir/subdir-n <= has access to directory listing of any sub-dir
** clientuser **
/dir <= DOES NOT have access to directory listing or parent dir (preferably Directory Index that points to a blank index.html file)
/dir/subdir-n <= has access to directory listing of any sub-dir
Basically we want our administrator to have be able to see all the list of sub dirs with an admin login and our individual clients to only be able to see their directory which we will communicate to them but all with the same login name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于不同的子目录使用不同的 htpasswd 文件应该可以实现这一点。
对于管理员用户,您创建一个登录名:密码对,并且在
/dir
中,您需要来自仅包含您的管理员用户登录名:密码的文件中的身份验证用户。对于 clientuser,您为该用户创建一个登录:密码对,并将管理员用户登录:密码对附加到该目录的同一 .htpasswd 文件中的新行上。
这样,您的管理员用户可以查看所有目录,而客户端用户只能查看自己的目录。
澄清一下,这里是您拥有的文件:
在 .htpasswdadmin 中,您将有一行:
admin:weofj2p8jöeoif2p84
在 .htpasswduser1 中,您将有两行:
请注意,您的 htpasswd 文件可以是任何名称,但最好以 .ht 开头,因为许多 apache 配置会阻止对此类文件名的 Web 访问。此外,您不应该像我的示例一样让 .htpasswd 文件在 webroot 中访问,而应将它们保存在无法从 Web 访问的文件夹中。最后一点:显然,您会看到它的局限性,当需要更改或添加新的管理员密码时,需要您将该 login:pw 对添加到所有子目录 .htpasswd 文件中。
如果有人对此有更好的解决方案,我会很好奇。
This should be possible with different htpasswd files for the different subdirectories.
For the adminuser you make a login:pw pair and in
/dir
you require a auth user from the file that has ONLY your adminuser login:pw.For the clientuser you make a login:pw pair for that user, and append the adminuser login:pw pair on a new line in the same .htpasswd file for THAT directory.
This way, your adminuser can look all dirs, while clientusers can only look their own dirs.
To clarify, here is the files you'd have:
In .htpasswdadmin you'd have one line:
admin:weofj2p8jöeoif2p84
In .htpasswduser1 you'd have two lines:
Note that your htpasswd files can be any name, but preferably start with .ht as many apache configs block web access to files name like that. Furthermore, you should not, as in my example, have your .htpasswd files accessible in the webroot, but rather keep them in a folder unaccessible from the web. And one last note: Obviously you see the limitations of that, when needing to change or add a new admin password requires you to add that login:pw pair to all the subdir .htpasswd files.
If anyone has a better solution to this, I would be very curious.