IIS网址从非www重定向到www不工作

时间:2017-05-05 12:13:00

标签: redirect iis

我有这个重写规则:

<rewrite>
  <rules>
    <rule name="Force non-WWW and SSL" enabled="true" stopProcessing="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
        <add input="{HTTPS}" pattern="off" />
      </conditions>
      <action type="Redirect" url="https://www.yourdomainname.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

它成功将 example.com 重定向到 https://example.com ,但是,我需要重定向到 https://www.example.com ,我可以这样做吗?

1 个答案:

答案 0 :(得分:0)

试试这个,只是限制域名或者你想要动态域名吗?

<rewrite>
      <rules>
        <rule name="Force non-WWW and SSL" enabled="true" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
            <add input="{HTTP_HOST}" negate="true" pattern="^www.(.*)$" ignoreCase="true" />
          </conditions>
          <action type="Redirect" url="https://www.example.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>     

使用匹配all和negate重定向