Options -MultiViews
DirectoryIndex index.html

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Local runtime adapter used by the versioned Blazor WASM bootstrap.
    RewriteRule ^_framework/dotnet-adapter\.php$ api/dotnet.php [QSA,L]
    RewriteRule ^_framework/runtime/([a-f0-9]{16})/([a-f0-9]{16})\.wasm$ api/runtime.php?version=$1&resource=$2 [QSA,L]
    RewriteRule ^_framework/runtime/([a-f0-9]{16})\.wasm$ api/runtime.php?resource=$1 [QSA,L]
    RewriteRule ^api/dotnet\.php$ - [L]
    RewriteRule ^api/runtime\.php$ - [L]

    # Same-origin HTTPS proxy for the API hosted on the VPS.
    RewriteRule ^api(?:/.*)?$ api/index.php [QSA,L]
    RewriteRule ^api-files(?:/.*)?$ api/index.php [QSA,L]

    # Blazor WebAssembly client-side routes.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.html [L]
</IfModule>

<IfModule mod_mime.c>
    AddType application/wasm .wasm
    AddType application/octet-stream .dll
    AddType application/json .json
</IfModule>

<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"

    <FilesMatch "^(index\.html|appsettings(\.[A-Za-z]+)?\.json|service-worker\.js)$">
        Header set Cache-Control "no-cache, no-store, must-revalidate"
    </FilesMatch>

    <FilesMatch "\.(wasm|dll|dat|blat|webcil)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>
</IfModule>

SetEnvIf Authorization "(.+)" HTTP_AUTHORIZATION=$1
