user1171048
user1171048

Reputation: 49

IIS7 Redirect pattern

Using IIS7 with rewrite module to create a redirect

Source request URL: http://www.domain.com/term/code.html?Product=55824 Should redirect to http://www.domain.com/product/55824

Current Rule (does not work)

<rule name="PatternRedirect" stopProcessing="true">
          <match url="term/([a-z]+)(.*)Product=([0-9]+)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="www.domain.com$" />
          </conditions>
          <action type="Redirect" url="http://www.domain.com/product/{R:3}"
            redirectType="Permanent" />
</rule>

Any ideas why the above isnt working?

Thanks

Upvotes: 0

Views: 717

Answers (1)

Tomek
Tomek

Reputation: 3279

Query string is not included in main match string, you have to use Conditions to evaluate it.

<rule name="PatternRedirect" stopProcessing="true">
          <match url="^term/.*" />
          <conditions  trackAllCaptures="true">
            <add input="{QUERY_STRING}" pattern="Product=([0-9]+)" />         
            <add input="{HTTP_HOST}" pattern="^www.domain.com$" />
          </conditions>
          <action type="Redirect" url="http://www.domain.com/product/{C:1}"
            redirectType="Permanent" />
</rule>

Upvotes: 1

Related Questions