URL 重写模块的 outboundRules 的优先级
Priority for outboundRules for URL rewrite module
如果规则 #1 先命中,规则 #2 会被命中吗?或者它会在 IIS Url 重写模块的规则 #1 处停止。我正在尝试跳过具有特定来源的网络字体。
<outboundRules>
<rule name="Set Access-Control-Allow-Origin header">
<match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_ORIGIN}" pattern="(http(s)?://((.+\.)?(thestatbook\.com|localhost:3000)))" />
</conditions>
<action type="Rewrite" value="{C:0}" />
</rule>
<rule name="Enable CORS for Fonts">
<match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" />
<conditions>
<add input="{REQUEST_URI}" pattern="^[^\?]+\.(ttf|otf|eot|woff|woff2|svg)(\?.*)?$" />
</conditions>
<action type="Rewrite" value="*" />
</rule>
</outboundRules>
Will rule #2 get hit if rule #1 does first? Or will it stop at rule #1 for IIS Url Rewrite Module.
据我所知,两个 outboundRules 都会命中。它将首先 运行 "Set Access-Control-Allow-Origin header",然后 "Enable CORS for Fonts"。您可以编写一个简单的规则并使用 postman 对其进行测试。
规则如下:
此规则将修改 Access-Control-Allow-Origin 和 Server 变量。
<outboundRules>
<rule name="removingserverheader" enabled="true" stopProcessing="true">
<match serverVariable="RESPONSE_SERVER" pattern=".*" />
<action type="Rewrite" value="0" />
</rule>
<rule name="Enable CORS for Fonts">
<match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" />
<conditions>
<add input="{HTTP_ORIGIN}" pattern=".*" />
</conditions>
<action type="Rewrite" value="2" />
</rule>
</outboundRules>
结果:
如果您只想触发一条规则而不触发另一条规则。我建议您可以尝试使用 StopProcessing 标志。
意思是当规则动作被执行(即规则匹配)并且这个标志被打开时,意味着不再处理后续规则并将请求传递到IIS请求管道。默认情况下,此标志处于关闭状态。
规则如下:
<rewrite>
<outboundRules>
<rule name="removingserverheader" enabled="true" stopProcessing="true">
<match serverVariable="RESPONSE_SERVER" pattern=".*" />
<action type="Rewrite" value="0" />
</rule>
<rule name="Enable CORS for Fonts" enabled="true">
<match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" />
<conditions>
<add input="{HTTP_ORIGIN}" pattern=".*" />
</conditions>
<action type="Rewrite" value="2" />
</rule>
</outboundRules>
</rewrite>
结果:
如果规则 #1 先命中,规则 #2 会被命中吗?或者它会在 IIS Url 重写模块的规则 #1 处停止。我正在尝试跳过具有特定来源的网络字体。
<outboundRules>
<rule name="Set Access-Control-Allow-Origin header">
<match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_ORIGIN}" pattern="(http(s)?://((.+\.)?(thestatbook\.com|localhost:3000)))" />
</conditions>
<action type="Rewrite" value="{C:0}" />
</rule>
<rule name="Enable CORS for Fonts">
<match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" />
<conditions>
<add input="{REQUEST_URI}" pattern="^[^\?]+\.(ttf|otf|eot|woff|woff2|svg)(\?.*)?$" />
</conditions>
<action type="Rewrite" value="*" />
</rule>
</outboundRules>
Will rule #2 get hit if rule #1 does first? Or will it stop at rule #1 for IIS Url Rewrite Module.
据我所知,两个 outboundRules 都会命中。它将首先 运行 "Set Access-Control-Allow-Origin header",然后 "Enable CORS for Fonts"。您可以编写一个简单的规则并使用 postman 对其进行测试。
规则如下:
此规则将修改 Access-Control-Allow-Origin 和 Server 变量。
<outboundRules>
<rule name="removingserverheader" enabled="true" stopProcessing="true">
<match serverVariable="RESPONSE_SERVER" pattern=".*" />
<action type="Rewrite" value="0" />
</rule>
<rule name="Enable CORS for Fonts">
<match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" />
<conditions>
<add input="{HTTP_ORIGIN}" pattern=".*" />
</conditions>
<action type="Rewrite" value="2" />
</rule>
</outboundRules>
结果:
如果您只想触发一条规则而不触发另一条规则。我建议您可以尝试使用 StopProcessing 标志。
意思是当规则动作被执行(即规则匹配)并且这个标志被打开时,意味着不再处理后续规则并将请求传递到IIS请求管道。默认情况下,此标志处于关闭状态。
规则如下:
<rewrite>
<outboundRules>
<rule name="removingserverheader" enabled="true" stopProcessing="true">
<match serverVariable="RESPONSE_SERVER" pattern=".*" />
<action type="Rewrite" value="0" />
</rule>
<rule name="Enable CORS for Fonts" enabled="true">
<match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" />
<conditions>
<add input="{HTTP_ORIGIN}" pattern=".*" />
</conditions>
<action type="Rewrite" value="2" />
</rule>
</outboundRules>
</rewrite>
结果: