.htaccess if用于不同.htpasswd文件的语句

时间:2017-11-17 17:38:50

标签: apache .htaccess .htpasswd

我不完全确定这是可行的,但我有一个应用程序托管在几个不同的URL和几个不同的子域。

每个都有一个基本的受保护部分(使用htpasswd)。

我希望能够拥有一个htaccess文件,而不是拥有一堆指向不同文件的不同文件。

我有以下文件结构:

的.htaccess htpasswd的-domainone htpasswd的-domaintwo htpasswd的-domainthree

有没有办法做这样的事情?

<If "%{HTTP_HOST} == 'domainone'">
AuthUserFile /file/location/.htpasswd-domainone
</If>

<If "%{HTTP_HOST} == 'domaintwo'">
AuthUserFile /file/location/.htpasswd-domaintwo
</If>


<If "%{HTTP_HOST} == 'domainthree'">
AuthUserFile /file/location/.htpasswd-domainthree
</If>

考虑子域名?

1 个答案:

答案 0 :(得分:0)

假设Apache 2.4,以下工作:

Options -Indexes

AuthName Login
AuthType Basic
require valid-user

<If "%{HTTP_HOST} == 'sub.domain1.com'">
AuthUserFile /var/www/html/admin/.htpasswd-domain1
Deny from all
Satisfy any
</If>
<ElseIf "%{HTTP_HOST} == 'sub2.domain1.com'">
AuthUserFile /var/www/html/admin/.htpasswd-domain2
Deny from all
Satisfy any
</ElseIf>
<Else>
Allow from all
Satisfy any
</Else>
相关问题