密码通过htaccess保护多个目录

时间:2022-03-16 06:11:58

I am able to password protect directories via the htaccess file at the root of my site (I have to use one htaccess file in my site root because of my CMS). The issue I'm having is assigning users to each directory I want to protect. I can create multiple users and password protect multiple directories, but any user will work for any protected directory. For example:

我可以通过我网站根目录下的htaccess文件密码保护目录(由于我的CMS,我必须在我的网站root中使用一个htaccess文件)。我遇到的问题是将用户分配给我想要保护的每个目录。我可以创建多个用户和密码保护多个目录,但任何用户都可以使用任何受保护的目录。例如:

example.com/section-one should be private and accessed by user "one".

example.com/section-one应该是私有的,并由用户“one”访问。

example.com/section-two should be private and accessed by user "two".

example.com/section-two应该是私有的,并由用户“two”访问。

However any user will work on either section and once users log into one they have access to the others without being asked for a password. I know it is an issue with my htaccess file. I tried using but can't seem to figure out the formatting. All the information online shows how to do this for files, but directories just isn't as easy to find help on.

但是,任何用户都可以使用任何一个部分,一旦用户登录到一个用户,他们就可以访问其他用户而无需输入密码。我知道这是我的htaccess文件的问题。我尝试使用但似乎无法弄清楚格式。所有在线信息都显示了如何为文件执行此操作,但目录并不容易找到帮助。

I am using this:

我用这个:

<IfModule mod_authn_file.c>
SetEnvIf Request_URI "^/section-one.*$" private
AuthName "Password Needed"
AuthGroupFile /dev/null
AuthType Basic
AuthUserFile /www/server/.htpasswd
Require user one
Order Deny,Allow
Deny from env=private
Satisfy any
</IfModule>

<IfModule mod_authn_file.c>
SetEnvIf Request_URI "^/section-two.*$" private
AuthName "Password Needed"
AuthGroupFile /dev/null
AuthType Basic
AuthUserFile /www/server/.htpasswd
Require User two
Order Deny,Allow
Deny from env=private
Satisfy any
</IfModule>

1 个解决方案

#1


4  

.htaccess files are used for applying specific configuration directives to the directories in which they are located. It is not possible to use one .htaccess file to specify different configurations for different directories. You either need to put your access controls in the server/vhost configuration file or use one .htaccess per directory.

.htaccess文件用于将特定配置指令应用于它们所在的目录。无法使用一个.htaccess文件为不同的目录指定不同的配置。您需要将访问控制放在server / vhost配置文件中,或者每个目录使用一个.htaccess。

#1


4  

.htaccess files are used for applying specific configuration directives to the directories in which they are located. It is not possible to use one .htaccess file to specify different configurations for different directories. You either need to put your access controls in the server/vhost configuration file or use one .htaccess per directory.

.htaccess文件用于将特定配置指令应用于它们所在的目录。无法使用一个.htaccess文件为不同的目录指定不同的配置。您需要将访问控制放在server / vhost配置文件中,或者每个目录使用一个.htaccess。