Running React Apps on IIS when using routing

14th October 2018 - Angular, server

When you initially upload a react app to IIS, you’ll find that the routes you have created, such as will return a 404. This is because IIS is expecting content to be literally in the folder structure specified.

To allow the application to use javascript to route the requested location, we need to enable URL Rewriting in IIS via the Request Filtering setting.

We can then either set up the routing in the web.config or via the IIS manager.

<?xml version="1.0" encoding="UTF-8"?>
      <rule name="React Routes" stopProcessing="true">
        <match url=".*" />
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
        <action type="Rewrite" url="/" appendQueryString="false" />
Tags: , ,