.htaccess if 语句用于不同的 .htpasswd 文件
.htaccess if statements for different .htpasswd files
我不完全确定这是否可行,但我有一个应用程序托管在几个不同的 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>
考虑子域?
假设 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>
我不完全确定这是否可行,但我有一个应用程序托管在几个不同的 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>
考虑子域?
假设 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>