Mobile app version of vmapp.org
Login or Join
Fox8124981

: IIS URL Rewrite - Rewriting subfolders to query strings 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

@Fox8124981

Posted in: #Iis #UrlRewriting

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

www.example.com/abc -> www.example.com/test1.aspx?c=abc https://www.example.com/def -> 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/(.*)" />
<conditions>
<add input="{R:2}" pattern="^[a-zA-Z0-9_]*$" />
</conditions>
<action type="Redirect" url="/test1.aspx?c={C:0}" appendQueryString="true" />
</rule>

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Fox8124981

1 Comments

Sorted by latest first Latest Oldest Best

 

@Fox8124981

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 test.com/test.com/abc would satisfy the condition and not 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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme