# Copied verbatim into dist/ root by Vite on build — must live at the web
# root alongside index.html for Apache to pick it up. Assumes the app is
# served at the domain root (matches vite.config.js's default base "/"); if
# it's ever moved under a subdirectory, add `RewriteBase /that/path` below
# and set `base` in vite.config.js to match, or every rewrite here breaks.

RewriteEngine On

# Force HTTPS. Also required for passkeys/WebAuthn: the browser only allows
# navigator.credentials.* on a secure context, so serving over plain HTTP
# would break passkey sign-in/registration on top of the redirect itself.
# Checks X-Forwarded-Proto too since Hostinger-style hosting often
# TLS-terminates at a proxy in front of Apache — %{HTTPS} alone reads "off"
# in that setup even when the visitor is genuinely on HTTPS, which would
# otherwise redirect-loop.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# SPA fallback: this is a client-side-routed React Router app, so a direct
# request or refresh (F5) on a deep link like /monitoring/websites has no
# matching file on disk and 404s unless rewritten back to index.html, where
# the router picks up the current URL and renders the right screen.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.html [L]

# Don't leak directory contents for folders without an index.
Options -Indexes

# Never serve dotfiles (.env, .git, this .htaccess itself) even if one ever
# ends up copied into the build output by mistake.
<FilesMatch "^\.">
  Require all denied
</FilesMatch>

# Compress text-based assets.
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/javascript application/json
</IfModule>

# Long-cache hashed build assets; never cache index.html itself so deploys
# show up immediately instead of being stuck behind a stale cached shell.
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/css "access plus 1 year"
  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"
</IfModule>
<IfModule mod_headers.c>
  <FilesMatch "index\.html$">
    Header set Cache-Control "no-cache"
  </FilesMatch>
</IfModule>
