how to redirect website to main url?

asked 2021-11-18T06:18:09.633+00:00
Sudesh Sharma 176 Reputation points

Hey Guys,

I have created React nodejs app and hosted the app on the azure VM IIS webserver. I have defined below set of rules in web.config file

<add name="Access-Control-Allow-Origin" value="" />
<iisnode node_env="%node_env%" nodeProcessCountPerApplication="1" maxConcurrentRequestsPerProcess="1024" maxNamedPipeConnectionRetry="100" namedPipeConnectionRetryDelay="250" maxNamedPipeConnectionPoolSize="512" maxNamedPipePooledConnectionAge="30000" asyncCompletionThreadCount="0" initialRequestBufferSize="4096" maxRequestBufferSize="65536" uncFileChangesPollingInterval="5000" gracefulShutdownTimeout="60000" loggingEnabled="true" logDirectory="iisnode" debuggingEnabled="true" debugHeaderEnabled="false" debuggerPortRange="5058-6058" debuggerPathSegment="debug" maxLogFileSizeInKB="128" maxTotalLogFileSizeInKB="1024" maxLogFiles="20" devErrorsEnabled="true" flushResponse="false" enableXFF="false" promoteServerVars="" configOverrides="iisnode.yml" watchedFiles="web.config;
.js" nodeProcessCommandLine="C:\Program Files\nodejs\node.exe" />
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />


    <rule name="DynamicContent">
                          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
                     <action type="Rewrite" url="server.js"/>

              <rule name="Redirect HTTP to HTTPS" stopProcessing="true">
                <match url="(.*)" />
                    <add input="{HTTPS}" pattern="off" />
                <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
            <rule name="non-wwwtowww" stopProcessing="true">
                <match url="(.*)" />
                    <add input="{HTTP_HOST}" pattern="^xyz\.com$" />
                <action type="Redirect" url="{R:1}" />
            <rule name="Add the STS header in HTTPS responses">
                <match serverVariable="RESPONSE_Strict_Transport_Security" pattern=".*" />
                <action type="Rewrite" value="max-age=31536000" />


whenever I have tried to open my website directly from the browser its redirects to I want to redirect my website to I have defined a rewrite rule for server.js (It's important for node js applications). Please help me guys to resolve this issue.

Thanks, Guys in advance.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
4,561 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. answered 2021-11-23T10:37:30.893+00:00
    Ravi Kanth Koppala 2,736 Reputation points Microsoft Employee

    @Sudesh Sharma ,

    I see a negate pattern in the web.config (1st rule). A pattern can be negated by using the negate attribute of the <match> element. The rule action is performed only if the current URL does not match the specified pattern when this attribute is used. This can be used to specify a condition that checks if the requested URL is NOT a file - :
    <add input="{REQUEST_FILENAME}" matchType="isFile" negate="true">

    I feel, this condition is making the app redirect to server.js. Do you require the above attribute in your web.config? If not, can you comment and check if the URL redirection is working as expected.

    I hope that helps.

    Please 'Accept as answer' if the provided information is helpful to help others in the community looking for help on similar topics.

    No comments