use*_*623 0 iis node.js reactjs iis-10
观看了关于同一问题的几个主题。没有一个对我有用。问题是:我有从 create-react-app 设计的 ReactJS + Redux 应用程序。实际上它可以工作,但是当应用程序冲浪以不同于 root 的 URL 开始时,会抛出 404。安装iisnode并尝试了网络中推荐的不同重写规则,但没有任何效果。最后是这个:
<rule name="Redirect HTTP to HTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/>
</rule> -->
<rule name="Redirect non-existent paths to root">
<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="^/initialLogin/*" ignoreCase="true" negate="true" />
</conditions>
<action type="Redirect" url="/" appendQueryString="false" />
</rule>
</rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)
我唯一需要的是通过根 url 发送所有传入请求,并将其余地址传递给它,以便 SPA 可以正常工作。托管:AzureVM IIS:v10
编辑:另一个奇怪的事情是它iisnode可以处理 js 文件的重定向,但是我的应用程序呈现出来index.html,当我试图指向index.html处理程序时,它实际上向我显示了一个空白页面。
这web.config对我有用。希望它会帮助别人。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<!-- This part is responsible for URL rewrites -->
<rewrite>
<rules>
<rule name="ReactJS 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>
<!-- This allows CORS for testing purposes -->
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4093 次 |
| 最近记录: |