【问题标题】:.htaccess disable password protection if certain get parameter is set to certain value.htaccess 如果某些 get 参数设置为某个值,则禁用密码保护
【发布时间】:2016-01-14 16:21:56
【问题描述】:

我们尝试禁用密码保护以供内部使用。因此,我们希望能够向执行此操作的 url 添加一个参数。我们知道知道这个参数的每个人都可以访问该目录。现在我们已经尝试过:

RewriteEngine On
# Do the regex check against the URI here, if match, set the "require_auth" var
RewriteCond %{QUERY_STRING} !^$ 
RewriteRule (.*auth=mysecurehash.*) $1 [E=require_auth:false] 

#Auth stuff
AuthType Basic
AuthUserFile /.htpasswd
AuthName "Enter Username and Password"

# Setup a deny/allow
Order Deny,Allow
# Deny from everyone
Deny from all
# except if either of these are satisfied
Satisfy any
# 1. a valid authenticated user
Require valid-user
# or 2. the "require_auth" var is NOT set
Allow from env=!require_auth

这应该禁用anydir/anfile.any?auth=mysecurehash 的身份验证 但不幸的是它没有。

实际上现在每个人都可以访问 - 无需密码。

我们缺少什么?

【问题讨论】:

  • 您是否尝试将顺序更改为“允许,拒绝”?
  • 如果我更改,每个人都会被要求输入密码,无论是否设置了require_auth
  • 我们仍然无法找到解决此问题的方法。我真的很感激另一个答案。

标签: .htaccess authentication get password-protection


【解决方案1】:

将您的规则替换为以下内容

 RewriteCond %{QUERY_STRING} auth=mysecurehash [NC] 
 RewriteRule ^ - [E=require_auth:false] 

仅供参考,查询字符串不是 RewriteRule 指令中匹配的一部分,我们需要使用 RewriteCond 来匹配带有查询字符串的网址。

尝试以下方法:

 RewriteEngine on
 RewriteCond %{QUERY_STRING} auth=mysecurehash [NC] 
 RewriteRule ^ - [E=require_auth:false] 
#Auth stuff
AuthType Basic
AuthUserFile /.htpasswd
AuthName "Enter Username and Password"

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

【讨论】:

  • 感谢您提供的信息。不幸的是,身份验证仍然不起作用。现在所有用户都可以访问它。不管?auth=mysecurehash加不加。
  • 感谢您的努力。不幸的是,这导致 htaccess 总是要求输入密码(即使使用?auth=mysecurehash
  • 您还有其他想法吗?
【解决方案2】:

在 2.4 中,您可以通过 <If> 指令轻松完成。

对于 2.2,您可以尝试将所有不带/不带参数的请求重定向到特定的虚拟 URL,而不是使用

SetEnvIf Request_URI ^/virturl.html require_auth=false

然后

Order Deny,Allow
Deny from all
Satisfy any
Require valid-user
Allow from env=!require_auth

类似的东西

【讨论】:

    猜你喜欢
    • 2015-05-10
    • 2018-07-12
    • 1970-01-01
    • 1970-01-01
    • 2016-09-21
    • 1970-01-01
    • 1970-01-01
    • 2018-07-05
    • 1970-01-01
    相关资源
    最近更新 更多