gpt4 book ai didi

angular - IIS:找不到页面时重定向到索引

转载 作者:行者123 更新时间:2023-12-04 03:55:22 25 4
gpt4 key购买 nike

在我的 IIS 网站上,我托管了三个应用程序,主网站是一个 Angular 应用程序,当我有托管所有 API 的 API 应用程序和另一个托管在应用程序别名/vmenu/下的纯 javascript 项目的应用程序时。
每个请求来到 example.com/v/应该重定向到 /vmenu/我还没有将该重写规则添加到我的 web.config

<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite VMenu">
<match url="^v/(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$" />
<action type="Rewrite" url="api/{R:0}" appendQueryString="false" />
</rule>
</rules>
</rewrite>/>
</httpErrors>
</system.webServer>
</configuration>
然后对于我的 Angular 应用程序,我必须为以下目的制定规则:
If the app uses the Angular router, you must configure the server to return the application's host page (index.html) when asked for a file that it does not have.
Angular 文档建议做以下重写规则:
<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>
但是通过在我的 webconfig 中的规则下添加它,每个请求都会被重定向到 index.html 甚至是对 API 的请求。
那么我怎样才能制定一个规则,只将有 404 错误的页面重定向到 index.html?

最佳答案

您可以选择错误 404,然后在错误页面组件中选择“编辑”按钮。选择您想要的选项,如果您想将错误页面重定向到另一个 URL,您可以选择第三个单选按钮并输入 URL。
enter image description here
您也可以通过 Web.Config 更改上面的配置。您只需要在 标记上添加以下值。

<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="https://URL/" responseMode="Redirect" />
</httpErrors>

关于angular - IIS:找不到页面时重定向到索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63995542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com