Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

iis

rewrite

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>
like image 958
Lei Avatar asked Aug 19 '13 10:08

Lei


People also ask

Which HTTP method can append query string to URL?

Simply use: echo http_build_url($url, array("query" => "the=query&parts=here"), HTTP_URL_JOIN_QUERY); .

How can I append a query parameter to an existing URL?

This can be done by using the java. net. URI class to construct a new instance using the parts from an existing one, this should ensure it conforms to URI syntax. The query part will either be null or an existing string, so you can decide to append another parameter with & or start a new query.

How can I add or update a query string parameter?

set('PARAM_HERE', VALUE_HERE); history. pushState(null, '', url); This will preserve everything about the URL and only change or add the one query param. You can also use replaceState instead of pushState if you don't want it to create a new browser history entry.

How do I pass query string?

To pass in parameter values, simply append them to the query string at the end of the base URL. In the above example, the view parameter script name is viewParameter1.

How do I append a table to a query?

Append queries displays the Append dialog box to add additional tables to the current query. Append queries as new displays the Append dialog box to create a new query by appending multiple tables. The append operation requires at least two tables. The Append dialog box has two modes: Two tables: Combine two table queries together.

How do I append a string to a column in SQL?

This query returns records in one column named full_name: To append a string to another and return one result, use the || operator. This adds two strings from the left and right together and returns one result. If you use the name of the column, don’t enclose it in quotes. However, in using a string value as a space or text, enclose it in quotes.

How do I append a field to a query design grid?

Query design grid Double-click each field that you want to append. The selected fields appear in the Field row in the query design grid. The data types of the fields in the source table must be compatible with the data types of the fields in the destination table. Text fields are compatible with most other types of fields.

What does append do in SQL Server?

The append operation creates a single table by adding the contents of one or more tables to another, and aggregates the column headers from the tables to create the schema for the new table.


1 Answers

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>
like image 123
Lei Avatar answered Sep 21 '22 16:09

Lei