# -----------------------------------------------------------------------------
# SPA routing + cache-busting for self-hosted cPanel / Apache
# -----------------------------------------------------------------------------

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # Never rewrite real files/dirs (assets, sitemap, robots, etc.)
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]

  # Everything else falls back to index.html so React Router can handle it.
  RewriteRule ^ /index.html [L]
</IfModule>

# Fallback for hosts that ignore RewriteRule
ErrorDocument 404 /index.html

# -----------------------------------------------------------------------------
# Cache headers — HTML must NEVER be cached, hashed assets can live forever.
# This is what makes new deploys (including homepage swaps) appear immediately.
# -----------------------------------------------------------------------------
<IfModule mod_headers.c>
  # index.html / any .html / service worker: always revalidate
  <FilesMatch "\.(html)$">
    Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
    Header set Pragma "no-cache"
    Header set Expires "0"
  </FilesMatch>
  <FilesMatch "sw\.js$">
    Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
  </FilesMatch>

  # Hashed build assets (Vite adds a content hash) — safe to cache long-term
  <FilesMatch "\.(js|css|webp|avif|png|jpe?g|svg|woff2?)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>
</IfModule>
