4

I have configured wild-card sub domain mapping for my web application. I have changed "A" records in DNS settings for this. All requests to these new sub domains are working fine.

Ex: http://test1.foo.com, test2.foo.com

Later I configured IIS7 Canonical rewriting like the following:

<rewrite>
  <rules>
    <rule name="Enforce canonical hostname" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTP_HOST}" negate="true" pattern="^www\.foo\.com$" />
      </conditions>
      <action type="Redirect" url="http://www.foo.com/{R:1}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

After adding the above code, all the wild-card sub domains are routing to http://www.foo.com.

I want all sub domains should work with out any problem with applying canonical rewriting.

Please help me.

1 Answers1

1

This question is a little old, but see if this helps with the sub-domain issue. I haven't tested it, but I believe it should do what you need.

<rewrite>
  <rules>
    <rule name="Enforce canonical hostname - save subdomains" stopProcessing="true">
      <match url=".?" ignoreCase="false" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^([a-z.]+\.)?foo\.com$" />
        <add input="{HTTP_HOST}" pattern="^www\." negate="true" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="http://www.{C:1}foo.com{URL}" />
    </rule>
  </rules>
</rewrite>
Rob
  • 931
  • 6
  • 10