reactjs.net-coreiisserver

404 - File or directory not found. getting in windows server


I am using React for the frontend and .NET Core for the backend. Everything works fine in the local environment, but when I deploy into windows server, I get a 404 - File or Directory Not Found error. I haven't been able to find a solution. Please help me.enter image description here


Solution

  • React uses client-side routing, but IIS (or any server) handles server-side routing. Make sure you're configuring your server to serve the index.html for all routes. You can do this by updating the web.config file if you're using IIS:

    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="React Routes" stopProcessing="true">
              <match url=".*" />
              <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
              </conditions>
              <action type="Rewrite" url="/" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>