You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IIS部署Angular项目:路由刷新404问题求助

解决方案

你的IIS重写规则里有个致命错误——第三个条件完全阻止了规则触发:

<add input="{REQUEST_URI}" pattern="(.*)" negate="true" />

这个条件的意思是「请求URI不匹配任意字符」,但所有请求的URI都至少包含字符,所以这个条件永远不满足,导致整个规则根本不会执行。

修正步骤:

  • 删掉上述错误的条件
  • 确保重写目标指向你的Angular入口文件(通常是根目录的index.html)
  • 确认服务器已安装IIS URL Rewrite模块

修正后的完整规则配置:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="AngularJS Routes" 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>
  </system.webServer>
</configuration>

说明:

  • 前两个条件确保只有当请求的不是真实存在的文件或目录时,才触发重写
  • 重写到index.html后,Angular的路由系统会接管URL,解析/t1并加载对应组件
  • 修改后记得重启IIS站点,或者回收应用池让配置生效

内容的提问来源于stack exchange,提问作者iluv_dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 07:16:03