【发布时间】:2020-06-23 19:28:45
【问题描述】:
我是 Angular 的新手,并且已将应用程序部署在 wwwroot 文件夹之外的 IIS 10 上。 IIS 安装了 URL Rewrite,这是我正在使用的 web.config 文件的内容。
<?xml version="1.0" encoding="utf-8"?>
<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="./index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
在 index.html 文件中我有<base href="/">
当我构建应用程序时,这是我使用的命令:
ng build --base-href "/myapp" --prod
当我浏览到网站 https://servername/index.html 时,页面加载并且 URL 变为 https://servername/myapp/。
如果我尝试直接访问 https://servername/myapp/,我会收到服务器 500 错误,除非我先使用 https://servername/index.html。
我的最终目标是能够使用https://servername/myapp/?param1=123¶m2=321 但是,这只有在我首先访问 https://servername/index.html 时才有效。
【问题讨论】: