Home > Software engineering >  Redirecting to HTTPS in web. Config
Redirecting to HTTPS in web. Config

Time:02-05

I have added a new rule in a web.Config file to redirect to HTTPS. It is working in localhost, but once I deployed it to the Dev environment, redirecting is not working. How can I get this to work?

<system.webServer>
<rewrite>
<rules>                   
<rule name="Force HTTPS" enabled="true" stopProcessing="true">    
<match url=".*" ignoreCase="false"/>
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">            
<add input="{HTTPS}" pattern="off"/>
</conditions>                 
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent"/>       
</rule>                     
</rules>                     
</rewrite>
</system.webServer>

CodePudding user response:

Use this updated version:

<rewrite> 
    <rules> 
    <rule name="HTTPS force" enabled="true" stopProcessing="true"> 
    <match url="(.*)" /> 
        <conditions> 
            <add input="{HTTPS}" pattern="^OFF$" /> 
        </conditions> 
        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
    </rule> 
    </rules> 
</rewrite> 

CodePudding user response:

in my solution I use this config and it works:

<rule name="HTTP to HTTPS redirect for all requests" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
                <add input="{HTTPS}" pattern="off" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
        </rule>

I hope it's the solution for you!

  •  Tags:  
  • Related