Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 如何使用envif为某些子域而不是其他子域设置基本身份验证_.htaccess_Basic Authentication_.htpasswd - Fatal编程技术网

.htaccess 如何使用envif为某些子域而不是其他子域设置基本身份验证

.htaccess 如何使用envif为某些子域而不是其他子域设置基本身份验证,.htaccess,basic-authentication,.htpasswd,.htaccess,Basic Authentication,.htpasswd,多亏了stack overflow的一些优秀人员,我在dev.website.com上使用以下脚本获得了身份验证请求密码: SetEnvIfNoCase Host ^.*dev\.website\.com$ require_auth=true AuthUserFile /var/www/vhosts/website.com/.htpasswd AuthName "Password Protected" AuthType Basic Order Deny,Allow Deny from all S

多亏了stack overflow的一些优秀人员,我在dev.website.com上使用以下脚本获得了身份验证请求密码:

SetEnvIfNoCase Host ^.*dev\.website\.com$ require_auth=true
AuthUserFile /var/www/vhosts/website.com/.htpasswd
AuthName "Password Protected"
AuthType Basic
Order Deny,Allow
Deny from all
Satisfy any
Require valid-user
Allow from env=!require_auth
我还想让它在以下位置输入密码:myname.website.com mynamedev.website.com&devmyname.website.com。基本上,除了“www.website.com”和“website.com”之外,任何东西都可以


最简单的方法是什么?

我原以为你可以做到以下几点

SetEnv require_auth=true
SetEnvIfNoCase Host ^www\.website\.com$ require_auth=false
SetEnvIfNoCase Host ^website\.com$ require_auth=false
AuthUserFile /var/www/vhosts/website.com/.htpasswd
AuthName "Password Protected"
AuthType Basic
Order Deny,Allow
Deny from all
Satisfy any
Require valid-user
Allow from env=!require_auth
第一行将默认情况设置为身份验证是必需的,第二行是不需要身份验证的特定情况。

请尝试:

#set env "auth" only for subdomains
SetEnvIfNoCase host ^((?!www\.).+)\.website\.com$ auth=1
 #auth 
 AuthUserFile /var/www/vhosts/website.com/.htpasswd
 AuthName "Password Protected"
AuthType Basic   

 #Here is where we allow/deny
Order Deny,Allow
Satisfy any
Deny from all
Require user valid-user
Allow from env=!auth