2017-02-14 21 views

回答

0
This ended up working for me: 

<rewrite> 
     <rules>         
      <rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
       <match url="(.*)" /> 
       <conditions> 
        <add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
       </conditions> 
       <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" /> 
      </rule> 
     </rules>   
    </rewrite> 
0
<rewrite> 
     <rules> 
     <rule name="Non www HTTP to HTTPS" patternSyntax="ECMAScript" stopProcessing="true"> 
       <match url="(.*)" /> 
       <conditions> 
        <add input="{HTTPS}" pattern="off" /> 
        <add input="{HTTP_HOST}" pattern="^www" negate="true" /> 
       </conditions> 
       <action type="Redirect" url="https://www.{HTTP_HOST}{REQUEST_URI}" /> 
      </rule> 
      <rule name="Non www HTTPS to www HTTPS" patternSyntax="ECMAScript" stopProcessing="true"> 
       <match url="(.*)" /> 
       <conditions> 
        <add input="{HTTPS}" pattern="On" /> 
        <add input="{HTTP_HOST}" pattern="^www" negate="true" /> 
       </conditions> 
       <action type="Redirect" url="https://www.{HTTP_HOST}{REQUEST_URI}" /> 
      </rule> 
      <rule name="HTTP to HTTPS" stopProcessing="true"> 
       <match url="(.*)" /> 
       <conditions> 
        <add input="{HTTPS}" pattern="off" /> 
        <add input="{HTTP_HOST}" pattern="www*" /> 
       </conditions> 
       <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" /> 
      </rule> 
     </rules> 
    </rewrite> 
+0

我仍然有一个问题。 如果你去这里: https://www.skaljakke.dk/skaljakker-damer 这一切似乎都很好,但如果你删除了“www。”它会失败。你有什么建议吗? –

+0

@ user3305839您是否拥有包含www的SSL证书?和只是domain.com? Web服务器必须能够首先进行握手,然后进行重定向。如果您没有涵盖两者的证书,浏览器会检测到安全性异常。 – Josh

0

@Josh:您的回答适用于第一次请求。 它将以“https://www”结束,非常完美。 但是,如果我然后删除“www。”从地址,它会失败,像下面的图片。

Resulting page in Firefox