0
votes

I'm trying to find out how to write IIS URL Rewrite rule to redirect by the following rule:

For example:
s1.mysite.com/mypage.aspx?p=1 should be redirected to www.mysite.com/mypage.aspx?p=1.

But this redirection rule, should only work if URL starts with one of the following:

"s1", "s2", "s5" and contains ".aspx".

I started to write some Regex pattern for that "(s1\.|s2\.|s5\.)+(.)*(\.aspx)+", but actually, I don't even know if I'm on correct way.

After I will have the regex pattern, how I can tell IIS to redirect to exactly same url, just instead s1|s2|s5 it must be www.

1
This might be better-asked over on WebmastersRobertB

1 Answers

2
votes

This should get the job done:

<rewrite>
    <rules>
        <rule name="Redirect s1, s2 and s5 subdomains" stopProcessing="true">
            <match url="\.aspx$" />
            <conditions logicalGrouping="MatchAll">
                <add input="{HTTP_HOST}" pattern="^(s1|s2|s5)\.mysite\.com$" />
            </conditions>
            <action type="Redirect" url="http://www.mysite.com/{R:0}" appendQueryString="true" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>