简体   繁体   中英

Web.Config - URL rewrite to WWW, HTTPS and Primary Domain - URL Chain Problems?

Pretty new to this, but trying hard to understand.

I was able to redirect non-www to www, and http to https, but now I need to redirect a domain pointer to the primary. ie Domain2.com to Domain1.com. I am concerned about the URL chain and taking a hit on SEO. Should I put the domain redirect before the WWW\\https one?

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

Instead two rules you can create one rule with multiple conditions:

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

This rule will do the following:

  • Redirect all other domains (domain1.com, domain2.com and etc) to www.domain1.com
  • Redirect HTTP to HTTPS

This rule will make only one necessary redirect instead of multiple redirects as your current rules

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM