.htaccess basic auth by virtual host?

后端 未结 3 522
野的像风
野的像风 2021-01-02 04:31

I was wondering if it was possible to setup a conditional http basic auth requirement based on the virtual host URL in an .htaccess file.

For example what I want t

3条回答
  •  忘掉有多难
    2021-01-02 04:50

    Here's a solution similar to what Jon Lin proposed, but using RewriteCond to check the host name:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} =protected.hostname.com
    RewriteRule ^.*$ - [E=DENY:1]
    
    AuthUserFile /path/to/htpasswd
    AuthName "Password please"
    AuthType Basic
    
    Order Deny,Allow
    Satisfy any
    Deny from all
    Require valid-user
    Allow from env=!DENY
    

提交回复
热议问题