Rewriting rules not working as expected

Below is my rewriting rule. When I am browsing corredorpropiedades.cl it is coming up with https://www.jahrsenoret.cl, fine. But I am browsing www.corredorpropiedades.cl it isn’t working as the server comes up with https://www.corredorpropiedades.cl Any idea why ?

 <rewrite>
      <rules>
	  	<rule name="Non-canonical hostnames to www.YOURSITE.com" patternSyntax="ECMAScript" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^corredorpropiedades.cl$" />
                </conditions>
                <action type="Redirect" url="https://www.jahrsenoret.cl/{R:0}" />
        </rule>
        <rule name="HTTP to HTTPS redirect" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
        </rule>
	
      </rules>
    </rewrite>

Could it be because HTTP_HOST in your condition is looking for exactly corredorpropiedades.cl notice the ^ and $ symbols? when HTTP_HOST in your other case is going to be www.corredorpropiedades.cl and thus not meet the condition.

Maybe try…

<rule name="Non-canonical hostnames to www.YOURSITE.com" patternSyntax="ECMAScript" stopProcessing="true">
   <match url=".*" />
   <conditions logicalGrouping="MatchAny">
      <add input="{HTTP_HOST}" pattern="^corredorpropiedades.cl$" />
      <add input="{HTTP_HOST}" pattern="^www.corredorpropiedades.cl$" />
   </conditions>
   <action type="Redirect" url="https://www.jahrsenoret.cl/{R:0}" />
</rule>

Now this is off the top of my head first guess, but here we made specify multiple conditions and also put in logicalGrouping="MatchAny" to say that if any of the conditions are matched, to redirect.

See if this works for you. Hopefully you see where I am going with this. :slight_smile:

1 Like

I use the following site for validating .htaccess rules:

https://supiet2.tk/test?

1 Like

I am on an IIS and don’t use .htaccess

You restarted your appdomain right?

1 Like

Also works for non .htaccess sites.

I believe there are four accepted methods/protocols of prefixing a domain name:

  1. http://
  2. https://
  3. http://www.
  4. https://www.

Your answer fixed my issue. Thank you

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.