Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Sep 12 '09 at 10:30

This question came from our site for professional and enthusiast programmers.

add comment

1 Answer

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>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.