Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url rewrite http to https in iisnode

Using standard iis url rewrite module technique to redirect http to https does not work with iisnode.

I am having the following rule configuration to redirect http to https:

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

The problem is that requesting http://domain.net is redirected to the https://domain.net/server.js

Any ideas how to get rid of the "server.js" part of the url?

like image 359
Jan Blaha Avatar asked Nov 30 '25 20:11

Jan Blaha


1 Answers

Ok, the solution is simple. I just need to put HTTP -> HTTPS url rewrite rule at the top. Final configuration can then look like this:

<rewrite>
  <rules>
    <rule name="HTTP to Prod HTTPS redirect" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
    </rule>
    <!-- Don't interfere with requests for logs -->
    <rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="^[a-zA-Z0-9_\-]+\.js\.logs\/\d+\.txt$" />
    </rule>
    <!-- Don't interfere with requests for node-inspector debugging -->
    <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="^server.js\/debug[\/]?" />
    </rule>
    <!-- First we consider whether the incoming URL matches a physical file in the     /public folder -->
    <rule name="StaticContent">
      <action type="Rewrite" url="public{REQUEST_URI}" />
    </rule>
    <!-- All other URLs are mapped to the Node.js application entry point -->
    <rule name="DynamicContent">
      <conditions>
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
      </conditions>
      <action type="Rewrite" url="server.js" />
    </rule>
  </rules>
</rewrite>
like image 142
Jan Blaha Avatar answered Dec 03 '25 12:12

Jan Blaha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!