# Static hosting config for the Vite build (Apache / LiteSpeed).
# Lives in public/, so Vite copies it into dist/ on every build.

# Correct MIME types. Getting this wrong is what breaks module scripts:
# a .js served as application/octet-stream is rejected by the browser.
<IfModule mod_mime.c>
  AddType application/javascript .js .mjs
  AddType text/css            .css
  AddType image/svg+xml       .svg
  AddType application/json    .json
  AddType font/woff2          .woff2
</IfModule>

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml \
    application/javascript application/json image/svg+xml
</IfModule>

<IfModule mod_headers.c>
  # Vite fingerprints asset filenames, so a given URL's contents never
  # change -- safe to cache hard and skip revalidation entirely.
  <FilesMatch "\.(js|mjs|css|woff2|png|jpg|jpeg|webp|gif)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>

  # index.html points at the current hashed bundles, so it must always be
  # revalidated -- otherwise visitors keep requesting a bundle that is gone.
  <FilesMatch "\.(html|xml|txt)$">
    Header set Cache-Control "public, max-age=0, must-revalidate"
  </FilesMatch>

  Header set X-Content-Type-Options "nosniff"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

<IfModule mod_rewrite.c>
  RewriteEngine On

  # Force HTTPS.
  RewriteCond %{HTTPS} !=on
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # NO single-page-app fallback here, deliberately.
  #
  # The usual "rewrite everything to /index.html" rule exists so client-side
  # routes survive a refresh. This site has no client-side routes: App.tsx
  # renders one page and the nav uses hash anchors (#about, #projects), which
  # never reach the server. Adding the catch-all meant every made-up URL
  # returned 200 with the full homepage -- a soft 404. That invents unlimited
  # duplicate URLs for crawlers and shows up in Search Console as "Soft 404"
  # and "Duplicate, Google chose a different canonical".
  #
  # Letting missing paths 404 honestly is the correct behaviour. If real
  # client-side routing is ever added, reinstate the fallback then.
</IfModule>

# Serve the styled app shell for genuinely missing URLs, still with a 404
# status so crawlers are told the truth.
ErrorDocument 404 /index.html

# Don't hand out directory listings for folders without an index.
Options -Indexes
