Question

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?

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top