[英]IIS URL Rewrite Rule with Params
I am having a hard time getting a URL rewrite rule to work. 我很难让URL重写规则起作用。
I want this url: 我想要这个网址:
http://www.mysite.com/oldpage.aspx?oldid=123
To rewrite to: 重写为:
http://www.mysite.com/sub/newpage.aspx?newid=123
Here is what I have, but it's not working: 这是我所拥有的,但不起作用:
<rule name="Old2New" stopProcessing="true">
<match url="^oldpage.aspx?oldid=([0-9]+)" />
<action type="Rewrite"
url="/sub/newpage.aspx?newid={R:1}"
appendQueryString="true" />
</rule>
What am I missing? 我想念什么?
The regex index starts at 0 not 1. so your rule should be: regex索引从0而不是1开始。因此您的规则应为:
<rule name="Old2New" stopProcessing="true">
<match url="^oldpage.aspx?oldid=([0-9]+)" />
<action type="Rewrite"
url="/sub/newpage.aspx?newid={R:0}"
appendQueryString="true" />
</rule>
You can easily test your rule in IIS7 interface. 您可以在IIS7界面中轻松测试您的规则。
Use the conditions to catch the query string part {C:1}, like this: 使用条件来捕获查询字符串部分{C:1},如下所示:
<rule name="My rule" stopProcessing="true">
<match url="^oldpage\.aspx" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{QUERY_STRING}" pattern="oldid=([0-9]+)" />
</conditions>
<action type="Redirect" url="/sub/newpage.aspx?newid={C:1}" appendQueryString="false" />
</rule>
Tested and working. 经过测试和工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.