我正在尝试为IIS实施两个规则,以将非WWW重定向到WWW和将HTTP重定向到https。

http://zzz.com -> https://www.zzz.com
http://www.zzz.com -> https://www.zzz.com
https://zzz.com -> https://www.zzz.com


因此,我将其添加到了web.config中:

  <system.webServer>
<rewrite xdt:Transform="Insert">
  <rules>
    <rule name="Force WWW" enabled="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^[^www]" />
      </conditions>
      <action type="Redirect" url="https://www.zzz.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>
    <rule name="Force HTTPS" enabled="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" />
      </conditions>
      <action type="Redirect" url="https://www.zzz.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>




我的问题:

有什么方法可以将其结合到一条规则中吗?

最佳答案

是的,您可以将它们合并为一个,并为条件使用logicalGrouping并将其设置为Any,这将等效于“ OR”。例如:

<rule name="Force 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.zzz.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

关于asp.net-mvc - IIS将非www重定向到www并将HTTP重定向到https,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32490426/

10-17 02:39