I want to redirect any traffic on my website based on the following rule:

  • https://www.example.com/abc -> https://www.example.com/test1.aspx?c=abc
  • https://www.example.com/def -> https://www.example.com/test1.aspx?c=def

I would like the subfolder to pass a query string, I have tried the following code but sadly had no success:

<rule name="Reditect1" stopProcessing="true">
    <match url="^(.*)test.com/(.*)" />
        <add input="{R:2}" pattern="^[a-zA-Z0-9_]*$" />
    <action type="Redirect" url="/test1.aspx?c={C:0}" appendQueryString="true" />
  • maybe this answer can help you a little bit to get an idea? stackoverflow.com/questions/4799910/…
    – Josip Ivic
    Commented Jan 27, 2016 at 9:48
  • @JosipIvic: Thanks for the reference. This is what I based my initial rule upon. I was able to figure out a solution that I will put in the answers
    – Ron
    Commented Jan 27, 2016 at 13:49
  • please can you reverse that rewrite from query string to only domain and default file (example.com/index.asp?id=555&guid=dsfdsfsdfsd) to (example.com/index.asp)
    – Brusky
    Commented Jul 3, 2018 at 6:50

1 Answer 1


So, after more research and trial and error I was able to figure it out. Here is how I have it setup now.

 <rule name="Redirect1" stopProcessing="true">
        <match url="^(.*)$" />
                <add input="{R:0}" pattern="^(?!\s*$).+$"/>
                <add input="{R:0}" pattern="^[a-zA-Z0-9_]*$" />
        <action type="Redirect" url="/test1.aspx?client={C:0}" appendQueryString="true" />

The rule was setup at the site level and not the server level in IIS. Hence, the pattern matching ignored the domain name.

^(.*)test.com/(.*) - tried matching a test.com after the actual qualified domain name. So www.test.com/test.com/abc would satisfy the condition and not www.test.com/abc


The rule matches any URL that comes in - Pattern (.*)

The first condition ensures that anything following the qualified domain name has at least one non-space character

The second condition ensures there are no special characters in the part that is being parsed. This was my requirement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.