IIS URL使用多个查询字符串重写

Jay*_*Jay 9 iis-7 url-rewriting url-rewrite-module

我真的很新的URL重写和尝试重写/重定向多个查询,但似乎无法正常工作.由于这是搜索结果并且具有不同的过滤,因此查询可能会有所不同.例如,某些搜索我们可能有查询,t1=something而另一方面我们可能有t2=somethingelse,有时我们可能会将它们组合成:t1=something&t2=somethingelse

我使用IIS7与web.config,这是我到目前为止所做的:
这是我的示例链接

www.website.com/search/?t1=first&t2=second 
Run Code Online (Sandbox Code Playgroud)

我试过以下,其中没有实际工作:
(1)

<rewrite> 
    <rules> 
        <rule name="first" stopProcessing="true">
            <match url="search/" />
            <conditions trackAllCaptures="true">
                <add input="{QUERY_STRING}" pattern="t1=([0-9a-zA-Z]+)" />
            </conditions>
            <action type="Redirect" url="search/{C:1}/" appendQueryString="false" />
        </rule>

        <rule name="second" stopProcessing="true">
            <match url="search/" />
            <conditions trackAllCaptures="true">
                <add input="{QUERY_STRING}" pattern="t2=([0-9a-zA-Z]+)" />
            </conditions>
            <action type="Redirect" url="search/{C:1}/" appendQueryString="false" />
        </rule>
    </rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)

(2)

<rule name="a" stopProcessing="true">
    <match url="search2/" />
    <conditions trackAllCaptures="true">
        <add input="{QUERY_STRING}" pattern="t1=([0-9a-zA-Z]+)" />
        <add input="{QUERY_STRING}" pattern="t2=([0-9a-zA-Z]+)" />
    </conditions>
    <action type="Redirect" url="search2/{C:1}/{C:2}" appendQueryString="false" />
</rule>
Run Code Online (Sandbox Code Playgroud)

我真的很感激任何帮助.

谢谢.

小智 0

我想我应该分享我发现的内容的链接 -

可能的答案在这里

此外,要分隔多个参数,您可以使用管道运算符。例如,这样的事情:

parm1=(\w+)|parm2=(\w+)

使用 {C:1} 和 {C:2} 应用目标网址

所以,网址是这样的:

yourapp/list.aspx?parm1=abc&parm2=123

将导致反向引用如下 - {C:1}=abc 和 {C:2}=123