4 January, 2022

IIS Notes

Rewrite

The rewrite module must be installed. These rule are used to serve different Angular files that are dependent to the user-configured language under the same url.

The first two are for bookmarked Angular local routes, the files are served from the root and the Angular client is handling the route from there.

The third and fourth rule are for serving files that were built with the Angular CLI.

<configuration>
  <system.webServer>
      <rewrite>
        <rules>
            <rule name="login|dashboard|contacts|reports|import|users|admin" stopProcessing="true">
                <match url="^(login|dashboard|contacts|reports|import|users|admin)(.*)$" />
                <conditions>
                  <add input="{HTTP_COOKIE}" pattern="language=(de|fr)" />
                </conditions>
                <action type="Rewrite" url="dist/teach/{C:1}/" />
            </rule>
            <rule name="login|dashboard|contacts|reports|import|users|admin no language" stopProcessing="true">
                <match url="^(login|dashboard|contacts|reports|import|users|admin)(.*)$" />
                <action type="Rewrite" url="dist/teach/de/" />
            </rule>
            <rule name="Not API but with language cookie" stopProcessing="true">
                <match url="^(?!api|signalr\/)(.*)$" />
                <conditions>
                  <add input="{HTTP_COOKIE}" pattern="language=(de|fr)" />
                </conditions>
                <action type="Rewrite" url="dist/teach/{C:1}/{R:0}" />
            </rule>
            <rule name="Not API and no language cookie">
                <match url="^(?!api|signalr\/)(.*)$" />
                <action type="Rewrite" url="dist/teach/de/{R:0}" />
            </rule>
        </rules>
    </rewrite>
  </system.webServer>
</configuration>