I'm trying to do a simple redirect from the www subdomain to the root domain. After trying many variations, I'm stuck and hoping for help. Feeling sure it's something stupid, but can't see it. Here's the rule I'm using.

<rewrite>
  <rules>
    <rule name="Redirect to root" stopProcessing="true">
      <match url=".*"  />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^www.stitchamerica.com$" negate="true" />
      </conditions>
      <action type="Redirect" url="http://stitchamerica.com/{R:1}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

Input greatly appreciated.

有帮助吗?

解决方案

This works for me:

    <rewrite>
      <rules>
        <rule name="Remove WWW" stopProcessing="true">
          <match url="^(.*)$" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
          </conditions>
          <action type="Redirect" url="http://YOURSITE.com/{R:0}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top