使用查询字符串重写URL
问题描述:
我在IIS中使用Redirect类型编写重写规则。我希望新的url有一个新添加的查询字符串参数值。旧网址没有任何查询字符串值。
I am writing a rewrite rule in IIS with type Redirect. I want the new url to have a query string parameter value added newly to it. The old url does not have any query string values.
达到此目的的最佳方式是什么?
What is the best way to achieve this?
旧网址:abc.com/2017/Sample-Page
新网址:test.abc.com/2017/Sample- Page?redirect = y
<rule name="rewrite with query string" stopProcessing="true">
<match url="(.*)2017/Sample-Page(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="abc.com" />
</conditions>
<action type="Rewrite" url="http://test.abc.com/{R:0}?redirect=y"/>
</rule>
答
这有效:
<rule name="rewrite with query string" stopProcessing="true">
<match url="(.*)2017/Sample-Page(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="abc.com" />
</conditions>
<action type="Rewrite" url="http://test.abc.com/{R:0}?redirect=y"/>
</rule>