【问题标题】:IIS URL Rewrite with multiple query string使用多个查询字符串重写 IIS URL
【发布时间】:2012-10-22 12:06:52
【问题描述】:

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

我正在使用带有 web.config 的 IIS7,这是我迄今为止所做的:
这是我的示例链接

www.website.com/search/?t1=first&t2=second 

我尝试了以下方法,但没有一个真正起作用:
(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>

(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>

非常感谢任何帮助。

谢谢。

【问题讨论】:

  • 很遗憾没有人回复

标签: iis-7 url-rewriting url-rewrite-module


【解决方案1】:

另外,这篇文章可能会提供答案 -

Tracking Capture Groups Across Conditions setting

编辑:上面链接中的示例

注意 trackAllCaptures=true

<rule name="Back-references with trackAllCaptures set to true">
 <match url="^article\.aspx" >
 <conditions trackAllCaptures="true">
    <add input="{QUERY_STRING}" pattern="p1=([0-9]+)" />
    <add input="{QUERY_STRING}" pattern="p2=([a-z]+)" />  
 </conditions>
 <action type="Rewrite" url="article.aspx/{C:1}/{C:2}" /> <!-- rewrite action uses back-references to both conditions -->
</rule>

【讨论】:

  • 应该标记为答案!对我来说是一种享受。
【解决方案2】:

我想我会分享一个我发现的链接 -

possible answer here

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

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

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

所以,网址是这样的:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-22
    • 2013-10-10
    • 1970-01-01
    • 2021-02-04
    • 1970-01-01
    相关资源
    最近更新 更多