iis 将www重定向到https

ndasle7k  于 2023-02-23  发布在  其他
关注(0)|答案(1)|浏览(150)

我尝试将我的网站重定向到https://www,但无法正常工作
http://example.com-〉正在重定向到https://www.example.com
https://example.com-〉正在重定向到https://www.example.com
http://www.example.com-〉未重定向,应重定向到https://www.example.com
这里我有重定向:

<rules>
    <rule name="Remove trailing slash" stopProcessing="true">
        <match url="(.*)/$" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Redirect" url="{R:1}" redirectType="Permanent" />
    </rule>
    <rule name="HTTPS Redirect" enabled="true" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{HTTPS}" pattern="^OFF$" />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
    </rule>
    <rule name="Redirect to www" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{HTTP_HOST}" pattern="^m4music.ch$" />
        </conditions>
        <action type="Redirect" url="https://www.m4music.ch/{R:1}" />
    </rule> 
</rules>

有人知道吗?

xzlaal3s

xzlaal3s1#

请尝试以下重写规则代码:

<rewrite>
  <rules>
    <rule name="Redirect to HTTPS and www" stopProcessing="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTPS}" pattern="^OFF$" />
        <add input="{HTTP_HOST}" pattern="^(www\.)?(m4music.ch)$" />
      </conditions>
      <action type="Redirect" url="https://www.m4music.ch/{R:1}" redirectType="Permanent" />
    </rule>
    <rule name="Special case for HTTPS and www" stopProcessing="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTPS}" pattern="^ON$" />
        <add input="{HTTP_HOST}" pattern="^m4music.ch$" />
      </conditions>
      <action type="Redirect" url="https://www.m4music.ch/{R:1}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

相关问题