RewriteEngine On
RewriteBase /_frontend/

RewriteRule ^index\.html$ - [L]

# SSR flag ON: hashed assets are served from the VPS release - its hashes
# must win over any local build, and the fallback below must never answer
# an asset request with index.html (the browser would get HTML as JS).
# This directory's .htaccess overrides the root one for /_frontend/*, so
# the rule has to live HERE, not in public/.htaccess (2026-11-09).
RewriteCond /usr/www/users/vitecevo/live/var/vitec-ssr-on.flag -f
RewriteRule ^assets/(.*)$ https://vitec-ssr.evomedien.de/_frontend/assets/$1 [P,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^ index.html [L]

# ── Cache headers ────────────────────────────────────────────────────────────

# index.html: never cache — always fetch fresh so the browser picks up
# the latest hashed JS/CSS filenames after a deploy.
<Files "index.html">
    Header set Cache-Control "no-store, no-cache, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "0"
</Files>

# Hashed assets (JS, CSS, fonts, images inside /assets/):
# Vite appends a content hash to every filename, so these are immutable.
# Cache them for 1 year — a new deploy produces new filenames automatically.
<FilesMatch "\.(js|css|woff2?|ttf|eot|otf)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>
