【问题标题】:Limit access to an URL with query parameters使用查询参数限制对 URL 的访问
【发布时间】:2017-01-10 08:42:42
【问题描述】:

我需要一个 URL 只能供某些已定义的用户访问。 URL中有一个查询参数,就是判别器。

网址可能是这样的:

https://my.my.com/my-app/view/myView.xhtml?myQueryParam=allUsers

我在这种 apache 配置中的经验是 ~ 0 并且谷歌搜索了一下我可以设置这个:

RewriteEngine on
RewriteCond %{QUERY_STRING} myQueryParam=allUsers
RewriteRule "/my-app/view/myView[.]xhtml.*" - [E=no_auth_required:1]

<LocationMatch "/my-app/view/myView[.]xhtml.*">

               Require uniqueID user1ID user2ID

</LocationMatch>

xhtml? 之间也可以有额外的字符串,因此.*

这可行,但问题是它也拒绝访问 ex。到链接

https://my.my.com/my-app/view/myView.xhtml?myQueryParam=somethingElse

好像不打扰查询参数的值...

我错过了什么?

编辑:我忘了说我使用的是 Apache 2.2。

【问题讨论】:

  • myQueryParam=somethingElse 想要什么?
  • 重写对我来说一直是个谜。 .* 会带你一直到myQueryParam=allUsers 吗?
  • 奇怪,你打算用 no_auth_required 做点什么吗?
  • @revo 对于myQueryParam 的所有其他可能值没有限制。

标签: regex apache security configuration


【解决方案1】:

提供的解决方案适用于 Apache v2.4

通过Location* 指令中的If 指令检查环境变量值:

RewriteCond %{QUERY_STRING} myQueryParam=allUsers
RewriteRule . - [E=no_auth_required:1]

<Location "/my-app/view/myView.xhtml">
    <If "reqenv('no_auth_required') == 1">
        Require uniqueID user1ID user2ID
    </If>
</Location>

【讨论】:

  • 如前所述,不幸的是我使用的是 Apache 2.2。还是谢谢你。
【解决方案2】:

试试这个,基本上告诉 apache 匹配 xhtml 之后的任何东西,这不是问号。

RewriteEngine on
RewriteCond %{QUERY_STRING} myQueryParam=allUsers
RewriteRule "/my-app/view/myView[.]xhtml[^?]*" - [E=no_auth_required:1]

<LocationMatch "/my-app/view/myView[.]xhtml[^?]*">

               Require uniqueID user1ID user2ID

</LocationMatch>

【讨论】:

  • 感谢您的回答,但myQueryParam=something else时仍然拒绝访问。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-07
  • 2021-11-10
  • 2019-09-26
  • 2017-01-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多