1
votes

I need to set a 301 redirection for http requests but couldn't put the pieces I found together and achieve the wanted result. Since I'm not familiar with the concept, I hope title is not misleading.

Right now I'm trying this

<rule name="Redirect to https" enabled="true" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{HTTPS}" pattern="off" />
            <add input="{HTTP_HOST}" pattern="^www.example.com$" negate="true" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />

along with other micromanages rules

I need to set these conditions

https://example.com ---> https://www.example.com

http://example.com ---> https://www.example.com

http://www.example.com ---> https://www.example.com

https://example.com/abc/def ----> https://www.example.com/abc/def

http://example.com/abc/def ----> https://www.example.com/abc/def

http://www.example.com/abd/def ---> https://www.example.com/abc/def

basically, every non http and non www request should ve directed to "https://www..." format.

right now, rule I set is not working on http://example.com format.

I'm not even sure if this is redirection or rewrite but our SEO counselor insist on 301 redirection.

How can I set this rule?

1

1 Answers

1
votes

This rule should work for you:

<rule name="Redirect to https" enabled="true" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
    <add input="{HTTPS}" pattern="off" />
    <add input="{HTTP_HOST}" pattern="^www.example.com$" negate="true" />
  </conditions>
  <action type="Redirect" url="https://www.example.com/{R:1}" />
</rule>

I changes condition groupping to MatchAny and using www.example.com in redirect result url