0

i need to redirect from

www.domain.com to https://domain.com
http://www.domain.com to https://domain.com
http://domain.com to https://domain.com
I have the following lines of code and it works fine

  <system.webServer>
<rewrite>
   <rules>
    <rule name="SecureRedirect" stopProcessing="true">
        <match url="^(.*)$" />
        <conditions>
          <add input="{HTTPS}" pattern="off" />
          <add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" />

        </conditions>
        <action type="Redirect" url="https://{C:2}" redirectType="Permanent" />
      </rule>
    </rules>
  </rewrite>
  </system.webServer>

i take it from here

I want also rediredt from https://www.domain.com to https://domain.com
i add the following lines

 <rule name="Remove WWW" stopProcessing="true">
        <match url="^https://www.(.*)" />

        <action type="Redirect" url="http://{R:1}"  />
      </rule>

but it no redirect from https://www.domain.com to `https://domain.com

why?

Community
  • 1
  • 1
esty
  • 1

1 Answers1

0

You are the conditions snippet in between your <match> and <action> tags for https redirection.

Try this:

 <rule name="Remove WWW" stopProcessing="true">
    <match url="^(.*)$" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^https://www.domain\.com$" />
        </conditions>
    <action type="Redirect" url="http://{R:1}"  />
 </rule>
George
  • 6,006
  • 6
  • 48
  • 68