我需要编写一个重定向来删除某个特定的参数,但我希望重定向与传入的URL相同,只是没有参数.这就是我所拥有的,它不起作用.我想如果我把请求URI放在那里而不附加查询字符串,那么它会起作用但它会导致循环.有没有人这样做过?
<rule name="Remove parameters" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="page=([0-9]+)" />
</conditions>
<action type="Redirect" url="{REQUEST_URI}" appendQueryString="false" />
Run Code Online (Sandbox Code Playgroud)
jallen的答案的问题是整个查询字符串将被删除,如果你想维护它的某些部分,这可能不是理想的.另一种选择如下:
<rule name="Remove paging parameters" stopProcessing="true">
<match url="(.*)?$" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="(.*)(page=.+)(.*)" />
</conditions>
<action type="Redirect" url="{C:1}{C:3}" appendQueryString="false" />
</rule>
Run Code Online (Sandbox Code Playgroud)
page参数之前的所有内容page参数后的所有内容因此,我们使用重定向仅{C:1}{C:3}排除页面查询字符串.