UrlRewrite 2.0在IIS 8.5中没有从url中删除www



我在我的web配置文件中有这两条规则来强制https并从url中删除www。

 <rule name="Remove WWW" stopProcessing="true">
      <match url="^(.*)$" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^(https?://)?www.(.+)$" />
      </conditions>
      <action type="Redirect" url="{C:1}{C:2}" redirectType="Permanent"  appendQueryString="false"/>
    </rule>

    <rule name="Redirect to https" 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" appendQueryString="false" />
    </rule>

注:我已经在SO和几乎所有的博客上回答了几乎所有的问题,但还没有运气:(。

使用IIS URL重写从地址中删除www的正确方法

从HTTPS中删除WWW http://madskristensen.net/post/url-rewrite-and-the-www-subdomain

http://www.serverintellect.com/support/iis/url-rewrite-to-redirect-www-iis7/

http://www.bradymoritz.com/iis7-url-rewrite-remove-www-from-all-urls/

确保你把你的规则放到网上。配置在系统下。webServer -> rewrite ->规则。

这个应该可以帮你完成这项工作:

<system.webServer>
 <rewrite>
  <rule name="Redirect to https" stopProcessing="true">
     <match url="(.*)" />
     <conditions>
        <add input="{HTTPS}" pattern="Off" />
     </conditions>
     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
  </rule>
  <rule name="Remove WWW" patternSyntax="Wildcard" stopProcessing="true">
     <match url="*" />
     <conditions>
        <add input="{CACHE_URL}" pattern="*://www.*" />
     </conditions>
     <action type="Redirect" url="{C:1}://{C:2}" redirectType="Permanent" />
  </rule>
 <rewrite>
</system.webServer>

最新更新