htaccess使用密码保护特定的域


htaccess-protect a specific domain with password

我有3个域:

example.com
sub1.example.com
sub2.example.com

所有这些都指向一个服务器和一个文件夹。我想保护sub1.example.comsub2.example.com不使用密码访问根文件夹,但不是主域,它应该可以在没有密码的情况下访问根文件夹。我的意思是:

example.com      => allowed
sub1.example.com => blocked with password
sub2.example.com => blocked with password
sub1.example.com/* => allowed
sub2.example.com/* => allowed

*是一个可以是任何内容的文件夹。我试着在网上和这里找到它,但找不到,我该怎么做?

# ----------------------------------------------------------------------
# Password protect staging server
# Use one .htaccess file across multiple environments
# (e.g. local, dev, staging, production)
# but only password protect a specific environment.
# ----------------------------------------------------------------------
SetEnvIf Host staging.domain.com passreq
AuthType Basic
AuthName "Password Required"
AuthUserFile /full/path/to/.htpasswd
Require valid-user
Order allow,deny
Allow from all
Deny from env=passreq
Satisfy any