每个域不同的htpasswd文件

时间:2013-07-25 13:49:53

标签: apache .htaccess authentication basic-authentication .htpasswd

我有两个域名,例如foo.com和bar.com共享相同的文档根目录。 这些网站受.htaccess文件保护

AuthUserFile ../.htpasswd
AuthName "No Access"
AuthType Basic
<Limit GET POST PUT>
    require valid-user
</Limit>

如何根据主机设置AuthUserFile?

伪代码:

if (host == foo.com) {
    AuthUserFile ../.htpasswd_foo
} else {
    AuthUserFile ../.htpasswd_bar
}
AuthName "No Access"
AuthType Basic
<Limit GET POST PUT>
    require valid-user
</Limit>

如果无法做到这一点,还有其他方法可以为这两个域进行不同的登录吗?

1 个答案:

答案 0 :(得分:-1)

尝试设置如下:

#site1.com
setenvIfNoCase Host site1\.com pass_1
AuthType Basic
AuthName "Site1.com Login Required"
AuthUserFile "/home/userdir/.htpasswds/site1.pwd"
Require valid-user
Order allow,deny
Allow from all
Deny from env=pass_1
Satisfy any

#site2.com
setenvIfNoCase Host site2\.com pass_2
AuthType Basic
AuthName "Site2.com Login Required"
AuthUserFile "/home/user_dir/.htpasswds/site2.pwd"
Require valid-user
Order allow,deny
Allow from all
Deny from env=pass_2
Satisfy any