Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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和环境变量(如果环境不存在,则执行X)_.htaccess_Environment Variables_.htpasswd - Fatal编程技术网

.htaccess和环境变量(如果环境不存在,则执行X)

.htaccess和环境变量(如果环境不存在,则执行X),.htaccess,environment-variables,.htpasswd,.htaccess,Environment Variables,.htpasswd,早上好 我的.htaccess文件中有两个条目,我想让它们更具动态性 首先,我有一个非www到www的重定向 <IfModule mod_rewrite.c> RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^www\..+$ [NC] RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </IfModule> 我希

早上好

我的.htaccess文件中有两个条目,我想让它们更具动态性

首先,我有一个非www到www的重定向

 <IfModule mod_rewrite.c>
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
 </IfModule>
我希望这只在与上述相同的条件下运行,因此: 环境!=“本地” 环境!=“开发人员” url不包含.staging.com

希望你们中的一些人能对这个问题有所了解


非常感谢

对于mod_重写部分:

RewriteCond %{ENV:environment} != "dev" && != "local"
RewriteCond %{HTTP_HOST} {DOESNT_CONTAIN .staging.com}
将成为:

RewriteCond %{ENV:environment} !dev 
RewriteCond %{ENV:environment} !local
RewriteCond %{HTTP_HOST} !\.staging\.com
对于mod_auth部分,需要为主机和dev/local设置一个env变量:

SetEnvIfNoCase Host .staging.com noauth=true
SetEnvIf environment dev noauth=true
SetEnvIf environment local noauth=true
然后添加额外的
Allow
语句:

Allow from env=noauth

你能解释一下“SetEnvIfNoCase Host.staging.com noauth=true”这一行在做什么吗?我不太明白它的意思。它设置一个环境变量,由于
Allow from env
仅检查环境变量是否存在,因此必须使用
setenif
检查
environment
变量的值。
SetEnvIfNoCase Host .staging.com noauth=true
SetEnvIf environment dev noauth=true
SetEnvIf environment local noauth=true
Allow from env=noauth