<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Allow static assets" stopProcessing="false">
                    <match url=".*\.(ico|png|jpg|jpeg|gif|css|js|woff|woff2|svg)$" ignoreCase="true" />
                    <action type="None" />
                </rule>
                <rule name="Block fake non-html extension" stopProcessing="true">
                    <match url=".*\.(?!html$)[^.]+$" ignoreCase="true" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_URI}" pattern="^/sitemap.xml$" negate="true" ignoreCase="true" />
                        <add input="{REQUEST_URI}" pattern="^/opensearch.xml$" negate="true" ignoreCase="true" />
                    </conditions>
                    <action type="Rewrite" url="/err.php" appendQueryString="false" />
                </rule>
                <rule name="sitemap xml" stopProcessing="true">
                    <match url="^sitemap.xml$" ignoreCase="false" />
                    <action type="Rewrite" url="sitemap.php" appendQueryString="false" />
                </rule>
                <rule name="All to index" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <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.php?key={R:1}" appendQueryString="true" />
                </rule>
                <rule name="Rewrite images to img.php">
                    <match url="^(.*)\.(jpg|jpeg|png|gif|webp|ico)$" />
                    <action type="Rewrite" url="/admin/img.php?={R:1}" />
                </rule>
            </rules>
        </rewrite>
        <httpErrors errorMode="Custom" defaultResponseMode="File">
            <remove statusCode="500" subStatusCode="-1" />
            <remove statusCode="403" subStatusCode="-1" />
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" prefixLanguageFilePath="" path="/404.php" responseMode="ExecuteURL" />
            <error statusCode="403" prefixLanguageFilePath="" path="/err.php" responseMode="ExecuteURL" />
            <error statusCode="500" prefixLanguageFilePath="" path="/err.php" responseMode="ExecuteURL" />
        </httpErrors>
        <staticContent>
            <mimeMap fileExtension=".avif" mimeType="image/jpeg" />
        </staticContent>
    </system.webServer>
</configuration>