I would like to deploy react.js project on iis server at a subdomain.
The works I do below:
- BrowserRouter with basename
import { BrowserRouter } from 'react-router-dom';
<BrowserRouter basename="/Subdomain">
<App></App>
</BrowserRouter>
In App;
<Switch>
<Route exact path="/" component={Main} />
...
</Switch>
Add 'HomePage' at package.json
"homepage": "https://domain/subdomain/"
Install URL Rewrite for IIS and create web.config
https://www.iis.net/downloads/microsoft/url-rewrite
web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Text Requests" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_METHOD}" pattern="^GET$" />
<add input="{HTTP_ACCEPT}" pattern="^text/html" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Although I did iisreset, still getting error (404 - File or directory not found.) when open page at Link in BrowserRouter.
Thank you for your help.