使用 ISAPI-Rewrite 排除目录

发布于 2024-07-21 14:56:59 字数 442 浏览 3 评论 0原文

我试图用 ISAPI-Rewrite 排除一个目录(注意:这是 mod-rewrite 的 windows/iis 端口)。

我想要排除的目录是“api”,当它位于站点的根目录时。

这是我的规则:

RewriteRule ^(/api/)(.+)$ $1$2 [NC, L]

请求看起来像这样: /api/v2/users?usernames=scottw

不幸的是,查询字符串值始终被排除,并且 url 被重写为 /api/v2/users。

我的攻击假设是 (.+) 会捕获其他所有内容。

有什么建议么? 或者排除目录的更好方法?

谢谢

更新:我还简化了规则,但这也没有改变任何内容:

RewriteRule ^(/api/.+)$ $1

I am trying to exclude a directory with ISAPI-Rewrite (note: this is a windows/iis port of mod-rewrite).

The directory I want to exclude is "api" when it is at the root of the site.

Here is my rule:

RewriteRule ^(/api/)(.+)$ $1$2 [NC, L]

A request would look something like this:
/api/v2/users?usernames=scottw

Unfortunately, the querstring value is always being excluded and the url is being rewrittten as /api/v2/users.

I am attacking under the assumption that (.+) would capture everything else.

Any suggestions? Or a better way to exclude a directory?

Thanks

Update: I have also simplified the rule, but that has not changed anything either:

RewriteRule ^(/api/.+)$ $1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

壹場煙雨 2024-07-28 14:56:59

结果这里发生了两件事:

  1. 正则表达式应该是 ^(api/) 而不是 ^(/api)。 第一个“/”被排除。
  2. ISAPI_Rewrite 附带的正则表达式解析器工具似乎无法正确处理查询字符串。

最终看来有效的规则是:

RewriteRule ^(api/.+) $1 [NC,L]

Turns out there are two things going on here:

  1. The regex should be ^(api/) and not ^(/api). The first "/" is excluded.
  2. The regex parser tool which ships with ISAPI_Rewrite does not seem to handle querystrings properly.

The rule which finally appears to be working is:

RewriteRule ^(api/.+) $1 [NC,L]
む无字情书 2024-07-28 14:56:59

我有时发现“.+”工作得很奇怪,您可能会尝试切换到“..*”,我并不是说它会起作用,但可能值得一试。

I've seen sometimes '.+' works oddly, you might try to switch to '..*' I'm not saying it will work, but it might be worth a try.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文