Windows server2012r2 how to create multiple subdomain site

256 Views Asked by At

I'm creating an application that accepting users as sub-domains,
Ex: {user_id}.mywebsite.com, thus, every request has to be *.mywebsite.com.

Problem is that every sub domain has to be bind on the iis user1.mywebsite.com
user2.mywebsite.com etc etc
My question is, is there a way to set a domain site to accept every sub-domain request?

This is basically what I want to do something like this?

Is there any way to do it without adding every user as sub-domain to the iis site?
Thanks in advance.

1

There are 1 best solutions below

1
Lex Li On BEST ANSWER

You can set up a catch-all site and then use ARR to forward the traffic,

<system.webServer>
    <rewrite>
        <rules>
            <rule name="site1" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^(.*).site1.com$" />
                </conditions>
                <action type="Rewrite" url="http://localhost:8091/{R:0}" />
            </rule>
            <rule name="site2" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^(.*).site2.com$" />
                </conditions>
                <action type="Rewrite" url="http://localhost:8092/{R:0}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

Other supporting steps can be found in this blog post,