Hosting React + .NET 8 API on IIS
To serve your React app at www.example.com and a .NET 8 Web API under
www.example.com/api, publish the API into its own folder and configure IIS with
Add Application.
# 1. Publish your API
dotnet publish -c Release -o .\publish
# 2. Copy folders to server
D:\Sites\MySite\react-build (React build output)
D:\Sites\MySite\api (Web API publish output)
# 3. IIS setup
- Root site → points to react-build
- Add Application → Alias: api → Physical path: D:\Sites\MySite\api
- Assign a dedicated App Pool (No Managed Code)
# 4. SPA rewrite rule (exclude /api)
<rule name="SPA" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/api($|/)" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
# 5. Test
https://www.example.com/api/health
Keep the API and React app in separate subfolders under the same site root. This keeps deployments clean and avoids routing conflicts.

















