0
votes

I have a issue with the web.config and forcing SSLs. I have a rule for rewriting url, because Nette PHP site is hosted.

<rule name="Rewrite Admin" stopProcessing="true">
                  <match url="^admin/(.*)" ignoreCase="true"/>
                  <conditions logicalGrouping="MatchAll">
                      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />    
                  </conditions>
                  <action type="Rewrite" url="/admin/index.php" />
               </rule>

In case I use https in url, the request is always redirected to http. (https://example.com/admin -> example.com/admin). When I use rule for SSL force below for all requests then error occur (Too many redirects). (have a 2 rules in web.config)

<rule name="Redirect to https">
        <match url="(.*)"/>
        <conditions>
          <add input="{HTTPS}" pattern="Off"/>
          <add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
            <add input="{REQUEST_URI}" pattern="^/(node)" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/(cbre)" negate="true" />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
      </rule>

How to force ssl for action type "rewrite"?

Thanks for help

1

1 Answers

0
votes

I took your rule config but cannot reproduce the issue. So, to redirect HTTP traffic to HTTPS, I'd recommend you install a site extension called Redirect HTTP to HTTPS via Kudu.

  1. Open the browser and visit:

    https://<your-app-name>.scm.azurewebsites.net/SiteExtensions/#gallery
    
  2. In search box enter "redirect", then click Search button.

    enter image description here

  3. Select Redirect HTTP to HTTPS and click ADD button.

  4. Click Install button when the dialog opens.
  5. To make it available by clicking Restart Site button.