URL Rewrite with Query String

2019-09-18 01:11发布

问题:

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?

Old url: abc.com/2017/Sample-Page

New Url: 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>

回答1:

This worked:

<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>