Excluding a directory with ISAPI-Rewrite
-
22-08-2019 - |
Question
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
Solution
Turns out there are two things going on here:
- The regex should be ^(api/) and not ^(/api). The first "/" is excluded.
- 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]
OTHER TIPS
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.