3
votes

What I want to do is rewrite subdomains to the main application, and append the specified subdomain onto the query string. For instance, "http://a.main.com" should rewrite to "http://www.main.com/default.aspx?SD=a".

Here is my rewrite rule:

<rule name="SubDomain" stopProcessing="true">
  <match url="^$" />
  <conditions trackAllCaptures="false">
    <add input="{HTTP_HOST}" pattern="^([A-Za-z0-9]+)\.main\.com$" />
  </conditions>
  <action type="Rewrite" url="http://www.main.com/default.aspx?SD={C:1}" logRewrittenUrl="false" />
</rule>

When I navigate my browser to "http://a.main.com", I get a 404. However, when I change the rule to be a redirect rule instead, it redirects correctly. The fact that it works when set to redirect mode, but not when set to rewrite mode confuses me greatly. What's going on?

FYI my HOSTS file is set up so that www.main.com and a.main.com both point to 127.0.0.1. The web site's only binding in IIS7 has its Host Name property set to 127.0.0.1.

1

1 Answers

3
votes

The "http://www.main.com/" portion of the node's url property needed to be removed. Here's what it looks like now:

<action type="Rewrite" url="default.aspx?SD={C:1}" logRewrittenUrl="false" />

This works.