使用ISAPI-Rewrite排除目录

[英]Excluding a directory with ISAPI-Rewrite


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

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

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

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

Here is my rule:

这是我的规则:

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

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

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

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

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

不幸的是,querstring值总是被排除,url被重写为/ 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

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

2 个解决方案

#1


Turns out there are two things going on here:

事实证明,这里有两件事:

  1. The regex should be ^(api/) and not ^(/api). The first "/" is excluded.
  2. 正则表达式应该是^(api /)而不是^(/ api)。第一个“/”被排除在外。

  3. The regex parser tool which ships with ISAPI_Rewrite does not seem to handle querystrings properly.
  4. 与ISAPI_Rewrite一起提供的正则表达式解析器工具似乎不能正确处理查询字符串。

The rule which finally appears to be working is:

最终似乎有效的规则是:

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

#2


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.

我有时会看到'。+'很奇怪,你可能会尝试切换到'.. *'我不是说它会起作用,但它可能值得一试。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2009/05/19/e7a04caf7dff7df67cb7feab9524568a.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号