<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # Remove .html extension from URLs
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)\.html$ /$1 [L,R=301]

  # Redirect all requests to index.html for SPA routing
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ index.html [QSA,L]

  # Cache busting for assets
  <FilesMatch "\.js$|\.css$|\.woff$|\.woff2$|\.ttf$|\.otf$|\.eot$">
    Header set Cache-Control "max-age=31536000, public"
  </FilesMatch>

  # Cache policy for HTML
  <FilesMatch "\.html$">
    Header set Cache-Control "max-age=3600, must-revalidate"
  </FilesMatch>

  # Compression
  <IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
  </IfModule>
</IfModule>

# Security headers
<IfModule mod_headers.c>
  Header set X-Content-Type-Options "nosniff"
  Header set X-Frame-Options "SAMEORIGIN"
  Header set X-XSS-Protection "1; mode=block"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>
