0

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

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Remove {HTTP_HOST} condition. Does it redirect anywhere at all?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.