2016-04-30 54 views
0

我有一個問題,我似乎無法找到任何聯機解決方案。所有搜索都是用於http到https或非www到www,但前面沒有http。IIS不會將https://domain.com重定向到https://www.domain.com

我的網站將不會重定向https://domain.comhttps://www.domain.com。它將domain.com重定向到www.domain.com就好了,但只有當https輸入後纔會重定向,從而導致錯誤。

我有這樣的HTTP重定向到https:

<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> 

編輯:試驗後,它管理的正確重定向到http://domain.comhttps://www.domain.com(即沒有從s到與S和WWW)。

但仍無法從https://domain.comhttps://www.domain.com

回答

0

想通了,添加此之後:

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

而且最重要的是,在IIS中刪除主機名場「www.domain.com>網站綁定>編輯>主機名稱,並取消選中「需要服務器名稱指示」。讓我的域名進入這裏導致上面的代碼不起作用。我原本認爲這是必要的,但並非如此。