Wildcard subdomains in IIS7. Is it possible to make them like it is in Apache?

Is this possible to configure IIS7 to achieve the same functionality like Apache has regarding wildcard domains? I'm interested in routing user in ASP.NET web application based on subdomain user used in URL.

Something like is described here:

http://steinsoft.net/index.php?site=programming/articles/apachewildcarddomain

Thanks


The answer is No, IIS7 (still) does not support wildcard hostnames (see this). If you want to serve multiple domain on one website, the only workaround for now, as notandy suggested, is using a dedicated IP and doing it with DNS, which does support wildcards.

2013 Update

For completeness, IIS8 does not yet have this feature either.

2016 Update

Finally, IIS 10 in Windows 2016 supports wildcard subdomains.


Does IIS support wildcard host header? Can I capture and redirect *.mydomain.com to one web site?

The answer is Yes/No. Yes, because you are able to redirect *.mydomain.com to one web site. No, because the magic is in DNS and not IIS.

Here's how you do it:
At IIS MMC, configure a web site with NO host header, then assign an IP address to the site. (if you have one IP address in the box, then you can skip this). With this, the web site will bound to the specific IP and will listen to all HTTP requests send to the IP, and you are done :)

Next step is to make sure your name resolution works for the wildcard query and reply with the correct IP address. If you using Microsoft DNS service, it won't allow you to create a '*' A record (assuming you already created the domain zone in DNS MMC), you need to do the following:

  1. Navigate to %windir%\system32\dns\
  2. Find the zone file. E.g.
    mydomain.com.dns, open it with Notepad
  3. Add an entry. E.g.
    * A IP.IP.IP.IP
  4. Save the zone data file
  5. Reload the zone data in DNS MMC.

Take note that by doing this, all * will response to the IP that you configured earlier. E.g. abc.mydomain.com, www.mydomain.com, K2k.mydomain.com and etc.

To verify that it is working, try ping utility ping (insert anything here).mydomain.com and you should get replies from IP.IP.IP.IP

Then try browsing, http:// (insert anything here).mydomain.com/, you should get the same web page that you have configured.

Source


You cannot create a wildcard (*) A record in Microsoft's DNS, but you can create a wildcard CNAME. If all you are trying to do is direct all subdomains to a particular IP, this would work. For example, if you have an A record for www.mydomain.com, you could add a CNAME record for *.mydomain.com and point that at www.mydomain.com. The hostname in the request header will still be the subdomain, so your web app should be able to catch it and handle it if you want.


You can use IIS if you use the Web Platform Installer (http://www.microsoft.com/web/downloads/platform.aspx) and install the "URL Rewrite" module. If you add an "A" record like "*.example.com", this allows all sub-domains to be sent to your IIS server. In the IIS server you simply add a URL rewrite rule to the default website to do whatever you wish, such as redirect to another URL. When a user enters, say, "xyz.example.com", you could redirect to "example.com", and point all unknown subdomains to the root domain. The steps are:

  1. Install Web Platform Installer: http://www.microsoft.com/web/downloads/platform.aspx

    Run it, search for "URL Rewrite", and install it.

  2. Go to the default website, and open "URL Rewrite".

  3. Click "Add Rule(s)" on far right side.

  4. Name the rule and set the following:

    Requested URL: Matches the Pattern

    Using: Regular Expressions

    Pattern: (.*)

    Logical Grouping: Match All

  5. Add a new condition (click the "Add.." button), and set:

    Condition Input: {CACHE_URL}

    Check if input string: Matches the Pattern

    Pattern (modify as needed): (http|https)://(.*?)\.rootdomain\.tld

    Click [OK].

  6. Now scroll down to action and set:

    Action Type: Redirect

    Redirect URL (modify as needed): {C:1}://rootdomain.tld{R:0}

The "{C:#}" and "{R:#}" come from the test windows when you click the "Test pattern" buttons next to the regex pattern entries. You can match part of a server value and reuse it later.

Also, you may want to checkout this tip on passing on the HTTP/HTTPS in the URL (the "{C:1}" in step 6 above): http://weblogs.asp.net/owscott/url-rewrite-protocol-http-https-in-the-action