2014-03-13 43 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

相关问题