IIS: redirect to index when page not found

Igo*_*yuk 5 iis angular

In my IIS Website i have three applications hosted on it, the main website is an Angular App, when i have API application where all APIs are hosted and another application that is a pure javascript project hosted under application alias /vmenu/.

Each request that comes to example.com/v/ should be redirected to /vmenu/ and i've yet added that rewrite rule to my 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>
Run Code Online (Sandbox Code Playgroud)

Then for my Angular application i have to make a rule for the following purpose :

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.
Run Code Online (Sandbox Code Playgroud)

The Angular documentation suggest do make the following rewrite rule:

<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>
Run Code Online (Sandbox Code Playgroud)

But by adding it under rules in my webconfig each request is just redirected to index.html even requests to API.

So how could i make a rule to redirect only pages with 404 error to index.html?

sam*_*mwu 2

您可以选择错误 404,然后选择错误页面组件中的 \xe2\x80\x9cEdit\xe2\x80\x9d 按钮。选择所需的选项,如果要将错误页面重定向到另一个 URL,可以选择第三个单选按钮并输入 URL。

\n

在此输入图像描述

\n

您还可以通过Web.Config更改上面的配置。您只需在 <system.Webserver> 标记上添加以下值。

\n
<httpErrors>\n    <remove statusCode="404" subStatusCode="-1" />\n    <error statusCode="404" prefixLanguageFilePath="" path="https://URL/" responseMode="Redirect" />\n</httpErrors>\n
Run Code Online (Sandbox Code Playgroud)\n