在IIS服务器上使用Vite刷新问题创建的React应用程序,如果我转到特定的路由,然后刷新页面,它会显示HTTP错误500

vcudknz3  于 9个月前  发布在  React
关注(0)|答案(1)|浏览(80)

我用vite创建了一个react应用程序,现在我把它托管在本地IIS服务器上。如果我转到主页,它工作正常,所有路由都工作正常,但在转到另一个路由并试图刷新页面后,它给了我这个错误:

HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Detailed Error Information:
Module       IIS Web Core
Notification     Unknown
Handler      Not yet determined
Error Code       0x8007000d
Config Error     Configuration file '\\?\D:\General Store\dist\web.config' does not contain a root <configuration> tag
Config File      \\?\D:\General Store\dist\web.config
Requested URL    http://192.168.0.6:86/
Physical Path    
Logon Method     Not yet determined
Logon User       Not yet determined

Config Source:
    1: <rule name="ReactRouter Routes" stopProcessing="true">
    2:   <match url=".*" />

我该如何解决这个问题?
我尝试添加web.config并添加了以下代码:

<code>
   <?xml version="1.0"?>
   <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" />
                           <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
                       </conditions>
                       <action type="Rewrite" url="/" />
                   </rule>
               </rules>
           </rewrite>
       </system.webServer>
   </configuration>
</code>

我也尝试了.htaccess_redirects解决方案,但没有为我工作。

ergxz8rk

ergxz8rk1#

首先,您需要确保安装:下载URL重写模块2.1Link Here

  • 并按照配置:*
<?xml version="1.0"?>
<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" />
 <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
 </conditions>
 <action type="Rewrite" url="/" />
 </rule>
 </rules>
 </rewrite>
 </system.webServer>
</configuration>

相关问题