htaccess条件

Liz*_*ard 7 .htaccess conditional setenv .htpasswd

我在我的实时网站上设置了htpasswd身份验证,它运行良好,但我不想在开发环境工作时要求输入密码.

在我的httpd.conf文件中,我有:

SetEnv APP_ENV "development"
Run Code Online (Sandbox Code Playgroud)

在我的.htaccess档案中,我有:

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /path/to/file/.htpasswd
AuthGroupFile /dev/null
require valid-user
Run Code Online (Sandbox Code Playgroud)

我想知道是否有反正把有条件围绕htppasswd的东西,这样,当APP_ENVdevelopment我没有得到提示输入密码.

这可能吗?

Hor*_*Kol 6

如果你能够,你应该考虑升级到Apache 2.4(或最新的2.3 beta版本,因为2.4还没有完全发布).

可用的新功能之一是授权容器 - 使用Require指令定义访问要求更加简单.

你应该得到类似的东西:

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /path/to/file/.htpasswd
AuthGroupFile /path/to/file/groups

SetEnv APP_ENV "development"

<RequireAll>
  <RequireAny>
    <RequireAll>
      #main requirements
      Require group user
      #other conditions if needed for non-dev/non-local
    </RequireAll>

    <RequireAll>
      #allow direct if development
      Require env APP_ENV development
    </RequireAll>

    <RequireAll>
      <RequireAny>
        #allow loopback and local network
        Require ip 127.0.0.1
        Require ip 10.2
      </RequireAny>
    </RequireAll>
  <RequireAny>

  #other conditions if needed for everyone

  <RequireNone>
    #blacklist
  </RequireNone>
</RequireAll>
Run Code Online (Sandbox Code Playgroud)