Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

All,

I have spent almost a day trying to figure this out. I am helpless now after all the searches and want to reach out to the community.

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

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

The subfolder needs to be passed as a query string

I have tried this and it does not seem to work.

<rule name="Reditect1" stopProcessing="true">
                    <match url="^(.*)test.com/(.*)" />
                    <conditions>
                        <add input="{R:2}" pattern="^[a-zA-Z0-9_]*$" />
                    </conditions>
                    <action type="Redirect" url="/test.aspx?c={C:0}" appendQueryString="true" />
                </rule>

Any help is highly appreciated

share|improve this question

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

NOTE
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

Explanation

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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