简体   繁体   中英

How to append query string & value via IIS rewrite rule?

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM