如何在子目录 (.htaccess) 中使用不同的密码

发布于 2024-10-30 03:12:37 字数 266 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赠意 2024-11-06 03:12:37

如果您希望子目录需要与父目录相同的密码,则子目录中根本不需要.htaccess

或者您是否尝试在子目录中使用不同密码?

[更新:] 在这种情况下,您需要通过 FilesMatch 指令。保持子目录的 .htaccess 相同,并修改父目录的 .htaccess 以包含以下内容:(

<FilesMatch "\.(private|dirs|are|listed|here)">
    require valid-user
</FilesMatch>

似乎没有办法否定 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 a FilesMatch directive, for instance. Keep your subdirectory's .htaccess the same, and modify the parent's to include something like:

<FilesMatch "\.(private|dirs|are|listed|here)">
    require valid-user
</FilesMatch>

(It seems that there's no way to negate a FilesMatch regex; but I might be wrong about that.)

做个少女永远怀春 2024-11-06 03:12:37

.htaccess 适用于所有文件和子文件夹。具有以下树结构的 .htaccess 文件将通过密码保护 dir1/index.htmldir1/subdir1/index.htmldir1/subdir1/example。 html

- dir1
| - .htaccess
| - index.html
| - subdir1
  | - index.html
  | - example.html

要仅用密码保护 subdir1,请将 .htaccess 文件移至该子目录中。使用以下结构,受保护的文件为 dir1/subdir1/index.htmldir1/subdir1/example.html

- dir1
| - index.html
| - subdir1
  | - .htaccess
  | - index.html
  | - example.html

要使用密码保护除子目录之外的目录,需要附加 .htaccess文件需要放置在子目录中以覆盖父 .htaccess 文件的选项。

- dir1
| - .htaccess
| - index.html
| - subdir1
  | - .htaccess
  | - index.html
  | - example.html

dir1/subdir1/.htaccess 中:

Require all granted

dir1/index.html 需要密码,但 dir1/subdir1/ 中的文件不需要密码。请参阅 https://httpd.apache.org/docs/2.4/howto/access .html 了解有关要求所有已授予 的信息。

要求父文件夹使用一个密码,子文件夹使用不同的密码:

- dir1
| - .htaccess
| - index.html
| - subdir1
  | - .htaccess
  | - index.html
  | - example.html

dir1/subdir1/.htaccess 中使用不同的 AuthUserFile 或需要不同的用户/组/要求:

# Use a different list of Users for this directory
AuthUserFile /var/.htpassrd_subdir1

# Or require a different user
#require user subdir1User

# Or use a different type of authentication altogether
#AuthUserFile /var/www/subdirectory/.htdigest
#AuthName "Subdir1-Realm"
#AuthType Digest
#require valid-user

身份验证不能嵌套。将 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.

- dir1
| - .htaccess
| - index.html
| - subdir1
  | - index.html
  | - 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

- dir1
| - index.html
| - subdir1
  | - .htaccess
  | - index.html
  | - 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.

- dir1
| - .htaccess
| - index.html
| - subdir1
  | - .htaccess
  | - index.html
  | - example.html

In dir1/subdir1/.htaccess:

Require all granted

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:

- dir1
| - .htaccess
| - index.html
| - subdir1
  | - .htaccess
  | - index.html
  | - example.html

In dir1/subdir1/.htaccess use a different AuthUserFile or require a different user/group/requirement:

# Use a different list of Users for this directory
AuthUserFile /var/.htpassrd_subdir1

# Or require a different user
#require user subdir1User

# Or use a different type of authentication altogether
#AuthUserFile /var/www/subdirectory/.htdigest
#AuthName "Subdir1-Realm"
#AuthType Digest
#require valid-user

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文