如何在子目录 (.htaccess) 中使用不同的密码
Order Deny,Allow
AuthUserFile /var/www/subdirectory/.htpasswd
AuthName "Authorization Required"
AuthType Basic
require valid-user
^我的.htaccess 文件。
但是,父目录有密码。
我希望这个目录只要求一个密码(即使它要求第二个密码,第二个密码可以留空。尽管如此,我想删除第二个密码,因为它很烦人)。
Order Deny,Allow
AuthUserFile /var/www/subdirectory/.htpasswd
AuthName "Authorization Required"
AuthType Basic
require valid-user
^my .htaccess file.
However, the parent directory has a password.
I want this directory to ask only for one password (even though it asks for the second password, the second password can be left blank. Despite this, i want to remove the second password because it is annoying).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望子目录需要与父目录相同的密码,则子目录中根本不需要
.htaccess
。或者您是否尝试在子目录中使用不同密码?
[更新:] 在这种情况下,您需要通过
FilesMatch
指令。保持子目录的 .htaccess 相同,并修改父目录的 .htaccess 以包含以下内容:(似乎没有办法否定 FilesMatch 正则表达式;但我可能是错的。)
If you want the subdirectory to require the same password as the parent directory, you don't need the
.htaccess
at all in the subdirectory.Or are you trying to use a different password in the subdirectory?
[Update:] In which case, you need to limit the parent's
require
to not include the subdirectory in question — through aFilesMatch
directive, for instance. Keep your subdirectory's .htaccess the same, and modify the parent's to include something like:(It seems that there's no way to negate a FilesMatch regex; but I might be wrong about that.)
.htaccess 适用于所有文件和子文件夹。具有以下树结构的 .htaccess 文件将通过密码保护 dir1/index.html、dir1/subdir1/index.html 和 dir1/subdir1/example。 html。
要仅用密码保护 subdir1,请将 .htaccess 文件移至该子目录中。使用以下结构,受保护的文件为 dir1/subdir1/index.html 和 dir1/subdir1/example.html
要使用密码保护除子目录之外的目录,需要附加 .htaccess文件需要放置在子目录中以覆盖父 .htaccess 文件的选项。
在 dir1/subdir1/.htaccess 中:
dir1/index.html 需要密码,但 dir1/subdir1/ 中的文件不需要密码。请参阅 https://httpd.apache.org/docs/2.4/howto/access .html 了解有关
要求所有已授予
的信息。要求父文件夹使用一个密码,子文件夹使用不同的密码:
在 dir1/subdir1/.htaccess 中使用不同的 AuthUserFile 或需要不同的用户/组/要求:
身份验证不能嵌套。将 auth 添加到子目录将覆盖父目录上的身份验证配置。如果父文件夹和子文件夹均受密码保护,并且有人访问子文件夹中的文件,系统会提示他们输入单个密码;为子文件夹配置的密码。
.htaccess applies to all the files and subfolders. Your .htaccess file with the following tree structure would password protect dir1/index.html, dir1/subdir1/index.html, and dir1/subdir1/example.html.
To password protect only subdir1 move the .htaccess file into the subdirectory. With the following structure the protected files are dir1/subdir1/index.html and dir1/subdir1/example.html
To password protect a directory except for a subdirectory an additional .htaccess file needs to be placed in the subdirectory to override the options of the parent .htaccess file.
In dir1/subdir1/.htaccess:
Then dir1/index.html requires a password, but not the files in dir1/subdir1/. See https://httpd.apache.org/docs/2.4/howto/access.html for information on
Require all granted
.To require one password for the parent folder and a different password for the child folder:
In dir1/subdir1/.htaccess use a different AuthUserFile or require a different user/group/requirement:
The authentication cannot be nested. Adding auth to a subdirectory will override the authentication configuration on the parent directory. If both the parent and the child folder are password protected and someone visits a file in the child folder they are prompted for a single password; the password configured for the child folder.