IIS URL 重写模块:基于查询字符串重定向
我在根据查询字符串参数重定向到另一个 URL 时遇到一些问题。我想将输入 www.domain.com/signup.aspx?p=1 的用户重定向到:
www.domain.com/signup
<rule name="Signup Redirect 1" stopProcessing="true">
<match url="signup\.aspx\?p=1" />
<conditions logicalGrouping="MatchAll" />
<action type="Redirect" url="signup" redirectType="Temporary" />
</rule>
现在,当他们输入 www.domain.com/signup.aspx?p=2 时,他们必须转到:
www.domain.com/signup/promocode
<rule name="Signup Redirect 2" stopProcessing="true">
<match url="signup\.aspx\?p=2" />
<conditions logicalGrouping="MatchAll" />
<action type="Redirect" url="signup/promocode" redirectType="Temporary" />
</rule>
上述规则不起作用。这样做的正确方法是什么?提前致谢。
格·
马丁
I Have some problems with redirecting to another URL based on the query string parameters. I want to redirect users which enter www.domain.com/signup.aspx?p=1 to:
www.domain.com/signup
<rule name="Signup Redirect 1" stopProcessing="true">
<match url="signup\.aspx\?p=1" />
<conditions logicalGrouping="MatchAll" />
<action type="Redirect" url="signup" redirectType="Temporary" />
</rule>
Now when they enter www.domain.com/signup.aspx?p=2 they must go to:
www.domain.com/signup/promocode
<rule name="Signup Redirect 2" stopProcessing="true">
<match url="signup\.aspx\?p=2" />
<conditions logicalGrouping="MatchAll" />
<action type="Redirect" url="signup/promocode" redirectType="Temporary" />
</rule>
The above rules don't work. What is the right way to do this? Thanks in Advance.
Gr
Martijn
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用值来选择目的地的更可靠方法是使用重写映射。该映射本质上是一个查找表。这不需要为每个新路径创建新规则(以及根据每个请求的模式对 URL 进行额外评估)。
定义:
A more robust method of using a value to select a destination is to use Rewrite Maps. The map is essentially a lookup table. This doesn't require a new rule (and an additional evaluation of the URL against a pattern on every request) for every new path.
Definitions:
看看这样是否效果更好一点:
See if this works a bit better: