我正在尝试将具有查询字符串的请求重定向到其他域名。
我有一个简短的网址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"
。
答案 0 :(得分: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>