首页 > 解决方案 > 角度“资产”文件夹的 IIS URL 重写失败

问题描述

我正在尝试使用 URL 重写在 IIS 中部署 Angular 6 项目(具有延迟加载模块路由)。下面是我的文件夹结构

在此处输入图像描述

下面是我的 web.config 文件

<configuration>
<system.webServer>
  <rewrite>
    <rules>
      <rule name="Angular 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="/" />
      </rule>
    </rules>
     <outboundRules>
                       <rule name="CDN_ReWrite_Images" enabled="true" preCondition="IsHtml" stopProcessing="true">
                         <match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)/(assets)/(.*)" />
                         <action type="Rewrite" value="http://localhost:4300/{R:3}" />
                         <conditions>
                         </conditions>
                       </rule>
                       <preConditions>
                         <preCondition name="IsHtml" logicalGrouping="MatchAny">
                           <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                         </preCondition>
                       </preConditions>
    </outboundRules>
  </rewrite>
</system.webServer>
</configuration>

角度路线工作正常。这里的问题是当我的应用程序尝试访问资产文件夹的内容时,它会将资产作为 URL 的一部分。我尝试如下创建出站规则以忽略资产文件夹。但这行不通。

理想的路线应该是

http://localhost:4300/json/data_list.json

相反,它尝试访问

http://localhost:4300/assets/json/data_list.json

让我知道我在这里做错了什么。谢谢

标签: asp.netangulariisurl-rewritingiis-7.5

解决方案


推荐阅读