Wednesday, September 3, 2025

Never have to remove hhtps rewrite when runnign in localhost for development

 From Alvin

Just wanted to share a small fix that can save us all sometime during local development.

 

Instead of having to edit the web.config file every time we want to run an app without HTTPS locally, we can add one line to the existing HTTPS redirect rule that tells it to skip redirection for localhost

 

<add input="{HTTP_HOST}" matchType="Pattern" pattern="^localhost$" negate="true" />

 

Here’s how the full rule should look:

 

<rewrite>

  <rules>

    <rule name="HTTP to HTTPS Redirect" stopProcessing="true">

      <match url="(.*)" />

      <conditions>

        <add input="{HTTPS}" pattern="^OFF$" />

        <!-- Below line ensures localhost doesn't get redirected to HTTPS -->

        <add input="{HTTP_HOST}" matchType="Pattern" pattern="^localhost$" negate="true" />

      </conditions>

      <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />

    </rule>

  </rules>

</rewrite>