【问题标题】:IIS URL Rewrite for modifying query parameter on outbound redirect response用于修改出站重定向响应的查询参数的 IIS URL 重写
【发布时间】:2020-05-10 04:56:03
【问题描述】:
我正在尝试找出一种方法来修改 HTTP 302 Found(重定向)响应的 Location 标头中的单个查询字符串参数。
例如,如果响应中的 Location 标头是:
https://example.com/path?param1=a¶m2=z¶m3=c
我希望它改写为:
https://example.com/path?param1=a¶m2=b¶m3=c
这是否可以使用出站 IIS URL 重写规则?
【问题讨论】:
标签:
asp.net
iis
url-rewriting
url-rewrite-module
【解决方案1】:
根据你的描述,我建议你可以尝试使用下面的url重写规则来达到你的要求。
<outboundRules>
<!-- This rule changes the domain in the HTTP location header for redirection responses -->
<rule name="Change Location Header">
<match serverVariable="RESPONSE_LOCATION" pattern="^https://example.com/path?param1=a¶m2=(.+)¶m3=c" />
<conditions>
<add input="{RESPONSE_STATUS}" pattern="^301" />
</conditions>
<action type="Rewrite" value="https://example.com/path?param1=a¶m2=b¶m3=c"/>
</rule>
</outboundRules>