Redirect IIS:删除http并强制使用https

Redirect IIS:删除http并强制使用https,redirect,iis,url-rewriting,Redirect,Iis,Url Rewriting,我有一个简单的网站,我想消除万维网,并强迫它是https 我设法使其中3种可能的组合起作用,但最后一种组合被卡住了 ->(好的) ->(好的) ->(好的) ->(KO) 我使用的URL重写代码借用了这里的其他问题。我已启用以下两个规则: <rule name="Remove www" enabled="true" stopProcessing="true"> <match url="(.*)" negate="false"></match

我有一个简单的网站,我想消除万维网,并强迫它是https

我设法使其中3种可能的组合起作用,但最后一种组合被卡住了

  • ->(好的)
  • ->(好的)
  • ->(好的)
  • ->(KO)

我使用的URL重写代码借用了这里的其他问题。我已启用以下两个规则:

    <rule name="Remove www" enabled="true" stopProcessing="true">
      <match url="(.*)" negate="false"></match>
      <conditions>
        <add input="{HTTP_HOST}" pattern="^www\.(.*)$" />
      </conditions>
      <action type="Redirect" url="https://{C:1}/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>
    <rule name="Force HTTPS" enabled="true">
      <match url="(.*)" ignoreCase="false" />
      <conditions>
        <add input="{HTTPS}" pattern="off" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>


  • (*)→ 你知道我怎样才能应付这种情况吗


    谢谢

    您是否尝试更改规则的顺序?有时这可能会有所帮助。

    谢谢您的意见

    这就是我解决问题的方法

    <rule name="Remove www" enabled="true">
      <match url="(.*)" negate="false"></match>
      <conditions>
        <add input="{HTTP_HOST}" pattern="^www\.(.*)$" />
      </conditions>
      <action type="Redirect" url="https://{C:1}/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>
    
    <rule name="Force HTTPS" enabled="true" stopProcessing="true">
      <match url="(.*)" ignoreCase="false" />
      <conditions>
        <add input="{HTTPS}" pattern="off" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>
    
    在IIS中,我添加(恢复)了带有和不带www的域的绑定

    我的理由如下

    • 该网站可以处理www.website.tld和website.tld
    • URL重写规则将处理重定向

    对该站点的呼叫可能会删除www,也可能会移动到https。允许重写规则同时执行这两项操作(禁用停止处理)可以实现这一点。

    根据您的url重写规则,我已经创建了一个测试演示,效果很好。我建议您可以尝试使用失败请求跟踪来解决发生的问题。详情,你可以参考这个。
    CNAME Record    www     website.tld.