- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果主机是 dev.example.com 或 test.example.com,我想告诉 Apache 2.4.9 要求有效用户。这不起作用:
AuthType Basic
AuthName "Speak, friend, and enter."
AuthBasicProvider file
AuthUserFile /sites/example/conf/.htpasswd
AuthGroupFile /dev/null
SetEnvIfNoCase Host ^dev\.example\.com$ env_is_protected
SetEnvIfNoCase Host ^test\.example\.com$ env_is_protected
Require valid-user
Require not env env_is_protected
not env
无效
contrary to the documentation .
SetEnvIfNoCase Host ^dev\.example\.com$ env_is_protected
SetEnvIfNoCase Host ^test\.example\.com$ env_is_protected
<RequireAny>
Require valid-user
<RequireNone>
Require env env_is_protected
</RequireNone>
</RequireAny>
Because negated authorization directives are unable to return a successful result, they can not significantly influence the result of <RequireAny> directive. (At most they could cause the directive to fail in the case where they failed and all other directives returned a neutral value.) Therefore negated authorization directives are not permitted within a <RequireAny> directive.
SetEnv env_is_unprotected 1
SetEnvIfNoCase Host ^dev\.example\.com$ !env_is_unprotected
SetEnvIfNoCase Host ^test\.example\.com$ !env_is_unprotected
Require valid-user
Require env env_is_unprotected
The internal environment variables set by this directive are set after most early request processing directives are run, such as access control and URI-to-filename mapping. If the environment variable you're setting is meant as input into this early phase of processing such as the RewriteRule directive, you should instead set the environment variable with SetEnvIf.
SetEnvIf Host . env_is_unprotected
SetEnvIfNoCase Host ^dev\.example\.com$ !env_is_unprotected
SetEnvIfNoCase Host ^test\.example\.com$ !env_is_unprotected
Require valid-user
Require env env_is_unprotected
最佳答案
我就是这样做的。
(使用 Cj Case 很好的引文作为注释来解释细节。:D)
SetEnvIfNoCase HOST ^dev\.example\.com$ env_is_protected
SetEnvIfNoCase HOST ^test\.example\.com$ env_is_protected
<RequireAny>
<RequireAll>
# when the Require directive is negated it can only fail or return a neutral result,
# and therefore may never independently authorize a request
# (reason why we need an additional "all granted" here!)
Require all granted
Require not env env_is_protected
</RequireAll>
AuthType Basic
AuthName "Speak, friend, and enter."
AuthUserFile /sites/example/conf/.htpasswd
Require valid-user
</RequireAny>
关于Apache 2.4 如何仅对特定主机要求有效用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23966273/
抛开可读性...在效率和/或功能方面,我不清楚将声明放在外部(我的做法)或循环内部(在其他 SO 帖子中看到)之间的区别。或者就此而言,为什么要代码声明?这里有一些退化的例子......下面有更多评论
我是一名优秀的程序员,十分优秀!