我正在尝试在一个 IIS 站点上托管具有 NET7 api 的 React 应用程序。根文件夹中有这样的文件结构
Api 可以工作,因为我请求 /api/status healthcheck 方法,它返回 200。但是当我请求 /index.html 时,我得到 404 (未找到)。
你知道我应该如何设置重写规则或以其他方式配置它来获取 index.html 文件
这是我的 web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\api\my-app.exe" arguments=".\api\my-app.dll" stdoutLogEnabled="true" stdoutLogFile=".\iis-logs\" hostingModel="OutOfProcess" />
<directoryBrowse enabled="false" />
<httpErrors errorMode="DetailedLocalOnly" existingResponse="Auto" />
<rewrite>
<rules>
<clear />
<rule name="Stop process React routes" stopProcessing="true">
TODO: how to write rule to get index.html file ??
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您可以尝试修改web.config文件中的重写规则。以下是如何设置重写规则来服务 React 应用程序的 index.html 文件和其他静态资源:
<rewrite> <rules> <rule name="Serve React App" 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="/index.html" /> </rule> </rules> </rewrite>您需要根据您的具体项目结构和需求调整路径和配置。