URL重写从HTTPS中删除WWW

时间:2014-03-13 16:53:47

标签: iis url-rewriting https iis-8 url-redirection

我需要在IIS8上的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

1 个答案:

答案 0 :(得分:4)

我得到了这个规则。

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