Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS URL Rewrite with multiple query string

Im really new in URL Rewriting and trying to rewrite / redirect multiple query but seems not working. Since this is the search result and comes with different filtering the queries may vary. For example is some search we may have the query of t1=something and in the other we may have t2=somethingelse and sometimes we may combine them like: t1=something&t2=somethingelse

Im using IIS7 with web.config and here is what I have done so far:
This is my example link

www.website.com/search/?t1=first&t2=second 

I have tried the following and non of them actually worked:
(1)

<rewrite> 
    <rules> 
        <rule name="first" stopProcessing="true">
            <match url="search/" />
            <conditions trackAllCaptures="true">
                <add input="{QUERY_STRING}" pattern="t1=([0-9a-zA-Z]+)" />
            </conditions>
            <action type="Redirect" url="search/{C:1}/" appendQueryString="false" />
        </rule>

        <rule name="second" stopProcessing="true">
            <match url="search/" />
            <conditions trackAllCaptures="true">
                <add input="{QUERY_STRING}" pattern="t2=([0-9a-zA-Z]+)" />
            </conditions>
            <action type="Redirect" url="search/{C:1}/" appendQueryString="false" />
        </rule>
    </rules>
</rewrite>

(2)

<rule name="a" stopProcessing="true">
    <match url="search2/" />
    <conditions trackAllCaptures="true">
        <add input="{QUERY_STRING}" pattern="t1=([0-9a-zA-Z]+)" />
        <add input="{QUERY_STRING}" pattern="t2=([0-9a-zA-Z]+)" />
    </conditions>
    <action type="Redirect" url="search2/{C:1}/{C:2}" appendQueryString="false" />
</rule>

I would really appreciate any help.

Thanks.

like image 730
Jay Avatar asked Nov 01 '12 20:11

Jay


1 Answers

Also, this post might provide the answer -

Tracking Capture Groups Across Conditions setting

EDIT: the example from the link above

Note the trackAllCaptures=true

<rule name="Back-references with trackAllCaptures set to true">
 <match url="^article\.aspx" >
 <conditions trackAllCaptures="true">
    <add input="{QUERY_STRING}" pattern="p1=([0-9]+)" />
    <add input="{QUERY_STRING}" pattern="p2=([a-z]+)" />  
 </conditions>
 <action type="Rewrite" url="article.aspx/{C:1}/{C:2}" /> <!-- rewrite action uses back-references to both conditions -->
</rule>
like image 182
Red Storm Avatar answered Sep 19 '22 15:09

Red Storm