【问题标题】:.htaccess if statements for different .htpasswd files.htaccess if 语句用于不同的 .htpasswd 文件
【发布时间】:2017-11-17 17:38:50
【问题描述】:

我不完全确定这是否可行,但我有一个托管在几个不同 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 .htaccess .htpasswd


    【解决方案1】:

    假设 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-22
      • 1970-01-01
      • 2021-06-20
      • 2013-05-30
      • 1970-01-01
      • 2016-11-26
      • 2012-12-13
      相关资源
      最近更新 更多