<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  # SPA fallback — prerendered folders (e.g. engineering/index.html) are served as real files first
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule . /index.html [L]
</IfModule>

# Never cache HTML files - always fetch fresh
<FilesMatch "\.(html|htm)$">
  Header set Cache-Control "no-cache, no-store, must-revalidate"
  Header set Pragma "no-cache"
  Header set Expires 0
</FilesMatch>

# Cache hashed JS/CSS assets for 1 year (they change filename on each build)
<FilesMatch "\.(js|css)$">
  Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>

# Cache static images (flags, favicons, OG icons)
<FilesMatch "\.(png|jpe?g|gif|webp|svg|ico)$">
  Header set Cache-Control "public, max-age=31536000"
</FilesMatch>

# Cache self-hosted fonts
<FilesMatch "\.(woff2?|ttf|otf)$">
  Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>
