<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>

    <!-- Default Document -->
    <defaultDocument>
      <files>
        <clear />
        <add value="index.php" />
      </files>
    </defaultDocument>

    <!-- Static Content -->
    <staticContent>
      <!-- Cache Control for static files -->
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
    </staticContent>

    <!-- URL Compression -->
    <urlCompression doStaticCompression="true" doDynamicCompression="true" />

    <!-- HTTP Compression -->
    <httpCompression>
      <dynamicTypes>
        <add mimeType="application/javascript" enabled="true" />
        <add mimeType="application/json" enabled="true" />
        <add mimeType="application/rss+xml" enabled="true" />
        <add mimeType="application/xml" enabled="true" />
        <add mimeType="text/css" enabled="true" />
        <add mimeType="text/html" enabled="true" />
        <add mimeType="text/javascript" enabled="true" />
        <add mimeType="text/plain" enabled="true" />
        <add mimeType="text/xml" enabled="true" />
      </dynamicTypes>
      <staticTypes>
        <add mimeType="image/svg+xml" enabled="true" />
        <add mimeType="application/font-woff" enabled="true" />
        <add mimeType="application/font-woff2" enabled="true" />
      </staticTypes>
    </httpCompression>

    <!-- Custom Errors -->
    <httpErrors>
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" path="/index.php?action=404" responseMode="ExecuteURL" />
    </httpErrors>

    <!-- URL Rewrite Rules -->
    <rewrite>
      <rules>

        <!-- General pages -->
        <rule name="Add FAQ" stopProcessing="true">
          <match url="^add-faq\.html$" />
          <action type="Rewrite" url="index.php?action=add" appendQueryString="true" />
        </rule>

        <rule name="Add Question" stopProcessing="true">
          <match url="^add-question\.html$" />
          <action type="Rewrite" url="index.php?action=ask" appendQueryString="true" />
        </rule>

        <rule name="Show Categories" stopProcessing="true">
          <match url="^show-categories\.html$" />
          <action type="Rewrite" url="index.php?action=show" appendQueryString="true" />
        </rule>

        <rule name="General Actions" stopProcessing="true">
          <match url="^(search|open-questions|contact|glossary|overview|login|privacy)\.html$" />
          <action type="Rewrite" url="index.php?action={R:1}" appendQueryString="true" />
        </rule>

        <rule name="Login Alternative" stopProcessing="true">
          <match url="^(login)$" />
          <action type="Rewrite" url="index.php?action=login" appendQueryString="true" />
        </rule>

        <rule name="Forgot Password" stopProcessing="true">
          <match url="^forgot-password$" ignoreCase="true" />
          <action type="Rewrite" url="index.php?action=password" appendQueryString="true" />
        </rule>

        <!-- Start page -->
        <rule name="Index" stopProcessing="true">
          <match url="^index\.html$" />
          <action type="Rewrite" url="index.php" />
        </rule>

        <!-- Solution ID page -->
        <rule name="Solution ID" stopProcessing="true">
          <match url="^solution_id_([0-9]+)\.html$" />
          <action type="Rewrite" url="index.php?solution_id={R:1}" appendQueryString="true" />
        </rule>

        <!-- Bookmarks page -->
        <rule name="Bookmarks" stopProcessing="true">
          <match url="^bookmarks\.html$" />
          <action type="Rewrite" url="index.php?action=bookmarks" appendQueryString="true" />
        </rule>

        <!-- FAQ record page -->
        <rule name="FAQ Content" stopProcessing="true">
          <match url="^content/([0-9]+)/([0-9]+)/([a-z\-_]+)/(.+)\.htm(l?)$" />
          <action type="Rewrite" url="index.php?action=faq&amp;cat={R:1}&amp;id={R:2}&amp;artlang={R:3}" appendQueryString="true" />
        </rule>

        <!-- Category page with page count -->
        <rule name="Category with Page" stopProcessing="true">
          <match url="^category/([0-9]+)/([0-9]+)/(.+)\.htm(l?)$" />
          <action type="Rewrite" url="index.php?action=show&amp;cat={R:1}&amp;seite={R:2}" appendQueryString="true" />
        </rule>

        <!-- Category page -->
        <rule name="Category" stopProcessing="true">
          <match url="^category/([0-9]+)/(.+)\.htm(l?)$" />
          <action type="Rewrite" url="index.php?action=show&amp;cat={R:1}" appendQueryString="true" />
        </rule>

        <!-- News page -->
        <rule name="News" stopProcessing="true">
          <match url="^news/([0-9]+)/([a-z\-_]+)/(.+)\.htm(l?)$" />
          <action type="Rewrite" url="index.php?action=news&amp;newsid={R:1}&amp;newslang={R:2}" appendQueryString="true" />
        </rule>

        <!-- Sitemap -->
        <rule name="Sitemap" stopProcessing="true">
          <match url="^sitemap/([^\/]+)/([a-z\-_]+)\.htm(l?)$" />
          <action type="Rewrite" url="index.php?action=sitemap&amp;letter={R:1}&amp;lang={R:2}" appendQueryString="true" />
        </rule>

        <!-- Google sitemap -->
        <rule name="XML Sitemap" stopProcessing="true">
          <match url="^sitemap\.xml$" />
          <action type="Rewrite" url="sitemap.xml.php" />
        </rule>

        <rule name="Gzipped Sitemap 1" stopProcessing="true">
          <match url="^sitemap\.gz$" />
          <action type="Rewrite" url="sitemap.xml.php?gz=1" />
        </rule>

        <rule name="Gzipped Sitemap 2" stopProcessing="true">
          <match url="^sitemap\.xml\.gz$" />
          <action type="Rewrite" url="sitemap.xml.php?gz=1" />
        </rule>

        <!-- Tags page with page count -->
        <rule name="Tags with Page" stopProcessing="true">
          <match url="^tags/([0-9]+)/([0-9]+)/(.+)\.htm(l?)$" />
          <action type="Rewrite" url="index.php?action=search&amp;tagging_id={R:1}&amp;seite={R:2}" appendQueryString="true" />
        </rule>

        <!-- Tags page -->
        <rule name="Tags" stopProcessing="true">
          <match url="^tags/([0-9]+)/([^\/]+)\.htm(l?)$" />
          <action type="Rewrite" url="index.php?action=search&amp;tagging_id={R:1}" appendQueryString="true" />
        </rule>

        <!-- Authentication services -->
        <rule name="WebAuthn Services" stopProcessing="true">
          <match url="^services/webauthn(.*)" />
          <action type="Rewrite" url="services/webauthn/index.php" appendQueryString="true" />
        </rule>

        <!-- User pages -->
        <rule name="User Pages" stopProcessing="true">
          <match url="^user/(ucp|bookmarks|request-removal|logout|register)$" />
          <action type="Rewrite" url="index.php?action={R:1}" appendQueryString="true" />
        </rule>

        <!-- Setup without trailing slash -->
        <rule name="Setup Root" stopProcessing="true">
          <match url="^setup/(.*)" />
          <action type="Rewrite" url="setup/index.php" appendQueryString="true" />
        </rule>

        <!-- Update without trailing slash -->
        <rule name="Update Root" stopProcessing="true">
          <match url="^update/(.*)" />
          <action type="Rewrite" url="update/index.php" appendQueryString="true" />
        </rule>

        <!-- Administration pages (not API) -->
        <rule name="Admin Pages" stopProcessing="true">
          <match url="^admin/(?!api/)(.*)$" />
          <action type="Rewrite" url="admin/index.php" appendQueryString="true" />
        </rule>

        <!-- Administration API -->
        <rule name="Admin API" stopProcessing="true">
          <match url="^admin/api/(.*)" />
          <action type="Rewrite" url="admin/api/index.php" appendQueryString="true" />
        </rule>

        <!-- Private APIs -->
        <rule name="Private APIs" stopProcessing="true">
          <match url="^api/(autocomplete|bookmark/delete|bookmark/create|user/data/update|user/password/update|user/request-removal|user/remove-twofactor|contact|voting|register|captcha|share|comment/create|faq/create|question/create|webauthn/prepare|webauthn/register|webauthn/prepare-login|webauthn/login|translations)$" />
          <action type="Rewrite" url="api/index.php" appendQueryString="true" />
        </rule>

        <!-- Setup APIs -->
        <rule name="Setup APIs" stopProcessing="true">
          <match url="^api/setup/(check|backup|update-database)$" />
          <action type="Rewrite" url="api/index.php" appendQueryString="true" />
        </rule>

        <!-- REST API v3.0 -->
        <rule name="REST API v3" stopProcessing="true">
          <match url="^api/v3\.0/(.*)" />
          <action type="Rewrite" url="api/index.php" appendQueryString="true" />
        </rule>

        <!-- robots.txt -->
        <rule name="Robots" stopProcessing="true">
          <match url="^robots\.txt$" />
          <action type="Rewrite" url="robots.txt.php" appendQueryString="true" />
        </rule>

        <!-- llms.txt -->
        <rule name="LLMS" stopProcessing="true">
          <match url="^llms\.txt$" />
          <action type="Rewrite" url="llms.txt.php" appendQueryString="true" />
        </rule>

      </rules>
    </rewrite>

  </system.webServer>
</configuration>
