views:

580

answers:

1

Hi there,

I've written some rules for our static content subdomains so that, when they come into IIS, they are redirected to our www. subdomain.

The reason for this is that we have several subdomains being indexed by Google. However, when I create the urls, I am still able to view files at img1.mydomain.com with the statuscode being 200, rather than 301 as I would expect.

Am I doing something wrong?

<!-- Force img domains and non-www users to point at www. -->
<rule name="redirectImgJsAndNonWww" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^img1.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img2.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img3.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js1.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js2.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js3.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^mydomain.com$" />
  </conditions>
  <action type="Redirect" url="www.mydomain.com/{R:0}" redirectType="Permanent" />
</rule>

Many thanks for any help.

Update: It appears that I was missing the logicalGrouping flag, which was setting my rules to "MatchAll".

<rule name="Redirect to WWW" stopProcessing="true">
  <match url=".*" />
  <conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img1.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img2.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img3.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js1.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js2.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js3.mydomain.com$" />
  </conditions>
  <action type="Redirect" url="http://www.mydomain.com/{R:0}" redirectType="Permanent" />
</rule>
A: 

The question has now been answered.

It appears that I was missing the logicalGrouping flag, which was setting my rules to "MatchAll".

<rule name="Redirect to WWW" stopProcessing="true">
  <match url=".*" />
  <conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img1.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img2.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img3.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js1.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js2.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js3.mydomain.com$" />
  </conditions>
  <action type="Redirect" url="http://www.mydomain.com/{R:0}" redirectType="Permanent" />
</rule>
Dan Atkinson