【问题标题】:Web.Config - URL rewrite to WWW, HTTPS and Primary Domain - URL Chain Problems?Web.Config - URL 重写为 WWW、HTTPS 和主域 - URL 链问题?
【发布时间】:2018-06-30 18:26:16
【问题描述】:

对此很陌生,但很难理解。

我能够将非 www 重定向到 www,将 http 重定向到 https,但现在我需要将域指针重定向到主节点。即 Domain2.com 到 Domain1.com。我担心 URL 链并在 SEO 上受到打击。我应该把域重定向放在 WWW\https 之前吗?

<rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^[^www]" />
    <add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://www.domain1.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

<!-- Just add this?  Should it go in front of the other? -->
<rule name ="Redirect Domain2 to Domain1" enabled="true">
  <match url="(.*)" ignoreCase="true" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="domain2.com" />
  </conditions>
  <action type="Redirect" url="https//www.domain1.com/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>

【问题讨论】:

    标签: asp.net https url-rewriting url-redirection


    【解决方案1】:

    您可以创建一个具有多个条件的规则,而不是两条规则:

    <rule name="All in one rule" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAny">
            <add input="{HTTPS}" pattern="off" />
            <add input="{HTTP_HOST}" pattern="^www\.domain1\.com$" negate="true" />
         </conditions>
         <action type="Redirect" url="https://www.domain1.com{URL}" />
    </rule>
    

    此规则将执行以下操作:

    • 将所有其他域(domain1.com、domain2.com 等)重定向到www.domain1.com
    • 将 HTTP 重定向到 HTTPS

    此规则将只进行一次必要的重定向,而不是像您当前的规则那样进行多次重定向

    【讨论】:

    • 我花了一点时间才弄清楚维克多先生你在做什么。我会把它简化成我自己的术语。 1.如果不是https>>用Https重定向到主域。 2.如果base URL不完全匹配,用Https重定向到主域。优秀!谢谢楼主!
    • domain1.com{R:1}" appendQueryString="true" redirectType="Permanent" /> 我不确定 {URL} 参数的作用在你的身上。
    • appendQueryString="true" redirectType="Permanent" 并不是必须的,因为这个值是默认值。
    猜你喜欢
    • 1970-01-01
    • 2017-07-13
    • 2014-12-16
    • 2017-12-04
    • 2018-02-02
    • 2018-03-31
    • 1970-01-01
    • 2016-11-03
    • 1970-01-01
    相关资源
    最近更新 更多