views:

578

answers:

2

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

A: 

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.

Kevin Up
Thanks for the suggestion, but that isn't working either.
Scott Watermasysk
+1  A: 

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]
Scott Watermasysk
Turns out it can be even simpler. RewriteRule ^api/ - [NC,L]
Scott Watermasysk