当 URI 以 GUID 结尾时 IIS 重写

IIS rewrite when URI ends in a GUID

我正在尝试制定 IIS 重写规则,如果 URL 没有 以 GUID 结尾,我会寻找 API key custom header 并重写。我已经测试了以下内容并且 它在没有第二个条件 的情况下工作正常(这意味着它可以附加 header 如果它存在无论 URI 是什么),但是第二个条件本身就破产了。

我已经测试了这个正则表达式,它似乎工作正常。

<rules>
        <rule name="SpecificRewrite" stopProcessing="true">
          <match url="^(.*)" ignoreCase="true" />
          <conditions logicalGrouping="MatchAll">
            <add input="{HTTP_apikey}" pattern="^(.+)" ignoreCase="true" matchType="Pattern" />
            <add input="{REQUEST_URI}" pattern="([0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1})$" negate="true" />
          </conditions>
          <action type="Rewrite" url="{R:0}/{C:0}" />
        </rule>
      </rules>

{REQUEST_URI} 总是以 / 开头,而 url 从不匹配 ([0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1})$) 这样的模式,因此您需要在模式中包含前导斜杠.

<add input="{REQUEST_URI}" pattern="/([0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1})$" negate="true" />