# Enable Brotli Compression for supported files, only if they exist
RewriteEngine On

RewriteCond %{HTTP:Accept-Encoding} br
RewriteCond %{REQUEST_FILENAME}.br -f
RewriteRule ^(.*)$ $1.br [QSA,L]

<FilesMatch "\.(js|css|html|json|svg|xml)\.br$">
    Header set Content-Encoding br
</FilesMatch>

<FilesMatch "\.html(\.br)?$">
    Header set Cache-Control "no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "0"
</FilesMatch>

# Vite hashes the bundled assets (index-By6hfIGF.js), so they can be cached forever
<FilesMatch "-[A-Za-z0-9_-]{8}\.(js|css)(\.br)?$">
    Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>

# A page path can also be a content folder (devices/audio). mod_dir would redirect it to the internal
# /<env>/manuals path before the fallback below runs, so the redirect is switched off.
DirectorySlash Off

# A page path loads its prerendered file (own title, description, canonical), the URL stays as it is
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.md$ - [R=404,L]

# SPA fallback: the root .htaccess rewrites /manuals/* into this folder, every non-file path loads the app
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [L]
