RewriteEngine On
RewriteBase /

# Downloads are immutable to the verified release tag. Never silently
# redirect missing installers to the moving android-latest release or to
# a generic GitHub releases page: a missing/unverified binary must return 404.
# The tagged-portal-release gate requires every published download to exist.
#
# German URL Aliases
RewriteRule ^datenschutz/?$ privacy.html [L,QSA]
RewriteRule ^kontakt/?$ contact.html [L,QSA]

# Explicit routing for pages that share a name with a directory
RewriteRule ^downloads/?$ downloads.html [L,QSA]
RewriteRule ^models/?$ models.html [L,QSA]

# Force clean URLs without .html extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [L,QSA]

# Android APK & Application MIME types
<IfModule mod_mime.c>
    AddType application/vnd.android.package-archive .apk
    AddType application/octet-stream .aab
    AddType application/json .json
    AddType image/svg+xml .svg
</IfModule>

<IfModule mod_headers.c>
    # Privacy-by-design and browser security headers for static Apache hosting.
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set Permissions-Policy "accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(self), usb=()"
    Header always set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; font-src 'self'; connect-src 'self' http://localhost:* http://127.0.0.1:*; img-src 'self' data: https:; frame-ancestors 'self'; base-uri 'self'; form-action 'self'; object-src 'none'"

    # Download artifacts are immutable within one published build; revalidation
    # keeps clients current while allowing efficient CDN/browser caching.
    <FilesMatch "^ComputeMesh-Android\.(apk|aab|json)$">
        Header set Cache-Control "public, max-age=300, must-revalidate"
    </FilesMatch>
</IfModule>
