简体   繁体   中英

Rewrite rule to redirect from one language to other except certain pages

In my below mentioned redirection rule I am redirecting website "fr-ca" language to "en" language except onboarding pages. That means urls should not redirect to "en" language if the urls contains onboarding pages. But it is always redirecting to "en". Please let me know what is wrong in my rule. Thanks in advance.

  <rule name="Site-fr-CA to en" stopProcessing="false">
      <match url="^fr-ca(.*)$" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^(.*)www.TestSite.com(.*)$" ignoreCase="false" />
        <add input="{HTTP_HOST}" pattern="^fr-ca/onboarding(.*)$" negate="true" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="/en{R:1}" />
    </rule>

 </rules>

The issue is the HTTP_HOST in your second condition. Use PATH_INFO instead:

<rule name="Site-fr-CA to en" stopProcessing="false">
  <match url="^fr-ca(.*)$" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^(.*)www.TestSite.com(.*)$" ignoreCase="false" />
    <add input="{PATH_INFO}" pattern="^/fr-ca/onboarding(.*)$" negate="true" />
  </conditions>
  <action type="Redirect" redirectType="Permanent" url="/en{R:1}" />
</rule>

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