【问题标题】:redirect non-www to www for an internal page's url将非 www 重定向到 www 以获取内部页面的 url
【发布时间】:2018-11-16 02:09:09
【问题描述】:

我要重定向:

  • domain.co.uk 到 www.domain.co.uk 和
  • domain.co.uk/contact-us 到 www.domain.co.uk/contact-us。

我已经使用 ECMAScript 和通配符尝试了十几个 web.config 规则,但第一个已经完成,但第二个要么保持不变,要么重定向到 www.domain.co.uk,即主页。目前的例子如下:

  <rule name="Redirect domain.com to www" patternSyntax="Wildcard" stopProcessing="true">
      <match url="*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^domain.co.uk/*" />
      </conditions>
      <action type="Redirect" url="http://www.domain.co.uk/{C:1}/{R:0}"  />
    </rule>

【问题讨论】:

    标签: redirect url-rewriting web-config


    【解决方案1】:

    这将重定向到 www 版本,同时保留 HTTP 和 HTTPS 协议:

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

    【讨论】:

      猜你喜欢
      • 2016-09-11
      • 2011-06-24
      • 2019-03-09
      • 2011-11-05
      • 2013-12-20
      • 2021-05-07
      • 2018-11-25
      • 2015-08-03
      • 1970-01-01
      相关资源
      最近更新 更多