Jun 03

Solution 1: Create Multiple IIS Web Sites

Setup DNS Server

You have two options. Since you probably have a limited number of subdomains to manage, you can either list them out individually or just use a wildcard.

Wildcard method: Add the following entry into your DNS server and change the domain and IP address accordingly.

*.example.com IN A 1.2.3.4

Declare manually: Add an entry for each of the subdomains.

sub1.example.com IN A 1.2.3.4
sub2.example.com IN A 1.2.3.4
sub3.example.com IN A 1.2.3.4

Setup the Web Server

First make sure you have created a root directory for each of the subdomains, as if you are working with a new web site. Your directory might look like the following:

d:\inetpub\wwwroot\example.com\sub1\
d:\inetpub\wwwroot\example.com\sub2\
d:\inetpub\wwwroot\example.com\sub3\
d:\inetpub\wwwroot\example.com\js\
d:\inetpub\wwwroot\example.com\css\
d:\inetpub\wwwroot\example.com\img\

Next, we create a web site for each of the subdomains. Let’s create the first one and you can repeat this for all others.

  • Open IIS Management Console.
  • Click on the Web Sites folder and select New : Web Site.
  • Click on Next to continue.
  • Enter the description for your site then click Next. An example would be: sub1.example.com.
  • On the IP Address and Port Setting, enter sub1.example.com into the Host header for this Web site field.
  • On the next page, enter the path d:\inetpub\wwwroot\example.com\sub1\.
  • On the next page, select your options click Next and you’re done.

Now here’s the fun part. Since you have created a new site for each subdomain, but there are files that are shared across them, such as javascript, style sheets, and images. What you could do is to create a virtual directory to link them to each of the web sites. Here’s how you do it.

  • Right click on the subdomain you have just created in IIS Management Console and select New : Virtual Directory.
  • As an example we’ll share the style sheet folder (css). Click on Next and enter css in the Alias field.
  • Enter the path d:\inetpub\wwwroot\example.com\css\ into the Path field and click on Next.
  • Specify the permission on the next page and you’re done.

Solution 1: Summary

What we have accomplished here is we have separated your web site into multiple subdomains, while still keeping only one copy of the shared files across them.