【问题标题】:URLRewrite to add www for http and httpsURLRewrite 为 http 和 https 添加 www
【发布时间】:2015-03-29 09:04:49
【问题描述】:

我需要 url-rewrite(或任何其他方法)执行以下操作:

http://domain.com > http://www.domain.com
https://domain.com > https://www.domain.com

我已经看到很多帖子重定向到 www 和很多强制 https,但没有一个可以同时做到这两个。

谢谢

【问题讨论】:

    标签: asp.net iis url-rewriting


    【解决方案1】:

    这应该会有所帮助:

    <rule name="Redirect to www" stopProcessing="true">
      <match url="(.*)" />
      <conditions trackAllCaptures="true">
        <add input="{CACHE_URL}" pattern="^(.+)://" />
        <add input="{HTTP_HOST}" pattern="^domain\.com$" />
      </conditions>
      <action type="Redirect" url="{C:1}://www.domain.com/{R:1}" />
    </rule>
    

    【讨论】:

    【解决方案2】:

    我使用的这条规则是为 http 和 https 应用 WWW(只需复制和粘贴):

    <rule name="ensure www" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{CACHE_URL}" pattern="^(.+)://(?!www)(.*)" />
      </conditions>
      <action type="Redirect" url="{C:1}://www.{C:2}" redirectType="Permanent" />
    </rule>
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2019-04-19
      • 2018-12-30
      • 2017-12-04
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 2014-12-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多