IIS重写以删除某些查询字符串参数并重定向到原始请求的主机

jal*_*len 3 iis rewrite

我需要编写一个重定向来删除某个特定的参数,但我希望重定向与传入的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)

JDa*_*ips 6

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)
  • C:1 =匹配page参数之前的所有内容
  • C:2 =匹配本身,以及我们想要排除的内容
  • C:3 =匹配page参数后的所有内容

因此,我们使用重定向{C:1}{C:3}排除页面查询字符串.