11
votes

I'm running IIS 7 with the offical rewrite rule module installed. I'd like to create a rewrite rule to match this URL:

http://www.sample.com/en-us/test.aspx?q=keyword

After rewriting the expected result would be:

http://www.sample.com/en-us/test.aspx?q=keyword&flag=value

How can I create a rule to implement this?

I've tested the following rule, but no luck, it always got redirect loop error:

<rewrite>
    <rules>
        <rule name="test" stopProcessing="true">
            <match url="(.*)/test\.aspx(.(?!flag=value))*$" />
            <action type="Redirect" url="{R:0}&amp;flag=value" appendQueryString="false" logRewrittenUrl="true" />
        </rule>
    </rules>
</rewrite>
1

1 Answers

23
votes

Found the solution by myself, just share it.

<rewrite>
    <rules>
        <rule name="Redirect for download result page" stopProcessing="true">
            <match url="(.*)/test.aspx(.*)" />
            <action type="Redirect" url="{R:1}/test.aspx?rf=sp" appendQueryString="true" redirectType="Found" />
            <conditions>
                <add input="{QUERY_STRING}" pattern="flag=value" negate="true" />
            </conditions>
        </rule>
    </rules>
</rewrite>