【问题标题】:Conditional query string redirect条件查询字符串重定向
【发布时间】:2011-04-02 05:53:01
【问题描述】:

我正在尝试将具有查询字符串的请求重定向到不同的域名。

我有一个简短的 URL,http://short.url,我想将 http://short.url?hello 重定向到 http://long.url/?hello。所以查询字符串必须由重定向保留。为了让事情变得更复杂,我想将http://short.url?hello,hello2 改写为http://long.url/advanced.aspx/?hello,hello2

这是我现在的规则(只处理我的问题的第一部分)

<rewrite>
    <rules>
        <rule name="test" patternSyntax="ECMAScript" stopProcessing="true">
            <match url="~/?\w+" />
            <action type="Redirect" url="http://long.url/?{R:0}" redirectType="Found" />
        </rule>
    </rules>
</rewrite>

但是,我没有看到任何重定向。另外,有没有更好的方法来做到这一点?基本上我只想设置一个快捷方式来将查询传递给网站。这些不是永久性的,所以我使用redirectType="Found"

【问题讨论】:

  • FWIW,你可以编写一个 HttpHandler 并使用 C# 代码直接操作 URL 来做你想做的事(甚至直接使用 Global.asax)

标签: asp.net redirect web-config


【解决方案1】:

如果有人想要这样做:

<rules>
    <rule name="Basic" patternSyntax="ECMAScript" stopProcessing="true">
        <match url="\w*" />
        <action type="Redirect" url="http://longurl.com" redirectType="Found" />
        <conditions>
            <add input="{QUERY_STRING}" pattern="\w+" />
            <add input="{QUERY_STRING}" pattern="\," negate="true" />
        </conditions>
    </rule>
    <rule name="Advanced" patternSyntax="ECMAScript" stopProcessing="true">
        <match url="\w*" />
        <action type="Redirect" url="http://longurl.com/advanced.aspx" redirectType="Found" />
        <conditions>
            <add input="{QUERY_STRING}" pattern="^\w+(?=\,)" />
        </conditions>
    </rule>
</rules>

【讨论】:

    猜你喜欢
    • 2016-03-17
    • 2015-03-31
    • 1970-01-01
    • 1970-01-01
    • 2014-12-03
    • 2017-04-21
    • 2011-01-30
    • 1970-01-01
    相关资源
    最近更新 更多