2014-03-13 80 views
2

我需要在IIS8的URL重寫中設置一個規則,以從所有https請求中刪除www。URL Rewrite從HTTPS中刪除WWW

下面是我想要實現的。我不在乎我們是否從所有網址中刪除www。

http://sitename.com/sub  -> http://sitename.com/sub 
http://www.sitename.com/sub -> http://www.sitename.com/sub 

https://sitename.com/sub  -> https://sitename.com/sub 
https://www.sitename.com/sub -> https://sitename.com/sub 
+0

[正確的方法使用IIS URL重寫從地址刪除萬維網(的可能的複製http://stackoverflow.com /問題/ 7368665 /正確法去除的WWW的從-使用-IIS-URL重寫地址) –

回答

3

我明白了這個規則。

<rule name="Remove WWW" enabled="true" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions> 
     <add input="{HTTP_HOST}" pattern="^(www\.)(ccsportal\.com)" /> 
    </conditions> 
    <action type="Redirect" url="https://{C:2}/{R:1}" /> 
</rule> 

我還添加了上面這條規則,迫使所有的請求到https

<rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
     <add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
    </conditions> 
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" /> 
</rule> 
+0

最好是做在這兩種情況下永久重定向: <動作類型= 「重定向」 URL = 「https:// {C:2}/{R:1}」redirectType =「永久」/> Sergey

相關問題