# Disable directory listing
Options -Indexes

# Default directory index
DirectoryIndex index.html

# Serve index.html for SPA client-side routing (if file/dir doesn't exist)
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  # If the request is for an existing file or directory, serve it
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]
  # Otherwise rewrite to index.html
  RewriteRule ^ index.html [L]
</IfModule>

# Optional: small caching hints for static assets
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/* "access plus 1 week"
</IfModule>

<IfModule mod_headers.c>
  # No caching for app files — always fetch fresh
  <FilesMatch "\.(html|htm|js|css|json)$">
    Header set Cache-Control "no-store, no-cache, must-revalidate"
    Header set Pragma "no-cache"
  </FilesMatch>
  <FilesMatch "\.(png|jpg|jpeg|gif|svg)$">
    Header set Cache-Control "max-age=604800, public"
  </FilesMatch>
</IfModule>

# Prevent serving hidden files (like .env, .git)
<FilesMatch "^\..+">
  Require all denied
</FilesMatch>
