在我的IIS网站上,我托管了三个应用程序,当我具有托管所有API的API应用程序和另一个应用程序(该应用程序以/ vmenu /托管)的纯JavaScript项目时,主网站是Angular应用程序。
每个请求都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。
您也可以通过Web.Config更改上面的配置。您只需要在<system.Webserver>标记上添加以下值。
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="https://URL/" responseMode="Redirect" />
</httpErrors>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句