12

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.

1
  • 1
    It's is a shame nobody has ever replied Commented Feb 17, 2016 at 22:48

2 Answers 2

1

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>

Sign up to request clarification or add additional context in comments.

1 Comment

Should be marked as the answer! Worked a treat for me.
0

I thought I'd share a link of what I had found -

possible answer here

Also, to separate multiple parameters you can use a pipe operator. For example, something like this:

parm1=(\w+)|parm2=(\w+)

apply target URL with {C:1} and {C:2}

So, URL like this:

yourapp/list.aspx?parm1=abc&parm2=123

will result in back references as follows - {C:1}=abc and {C:2}=123

Comments

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.