条件查询字符串重定向
问题描述:
我试图重定向具有查询字符串的请求到不同的域名。条件查询字符串重定向
我有一个简短的网址,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"
。
答
如果有些人要做到这一点:
<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>
FWIW,你可以写一个HttpHandler的和操纵直接与C#代码的URL,做你想做什么(甚至可以直接使用在Global.asax) – 2011-04-01 18:24:34