IIS 中小写 WWW HTTP 的单一规则 URL 重写

Single Rule for lowercase WWW HTTPs in IIS URL Rewrite

我正在尝试创建一个 SINGLE 重写规则(以避免多次 301 重定向),它将所有请求转换为 https、小写、www 前缀。

因此,http://example.com/Page would be https://www.example.com/page - 全部在一条规则内。

我该怎么做?

<rule name="All in one URL" stopProcessing="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTPS}" pattern="off" />
        <add input="{REQUEST_URI}" pattern="[A-Z]" ignoreCase="false" />
        <add input="{HTTP_HOST}" pattern="^www\." negate="true" />
     </conditions>
     <action type="Redirect" url="https://www.example.com:35077{ToLower:{URL}}" />
</rule>

这条规则将起到这样的作用:

  • 小写URL
  • 强制使用 HTTPS
  • 必要时添加 www