# Site vitrine sur l'hébergement o2switch (Apache) : HTTPS, adresse sans « www », page 404,
# en-têtes de sécurité, cache et compression. Copié tel quel dans dist/ à la construction.

Options -Indexes
DirectoryIndex index.html
ErrorDocument 404 /404.html
AddDefaultCharset utf-8

<IfModule mod_rewrite.c>
  RewriteEngine On
  # « www » vers l'adresse principale, en HTTPS.
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
  # Toujours en HTTPS.
  RewriteCond %{HTTPS} !=on
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

<IfModule mod_headers.c>
  Header always set X-Content-Type-Options "nosniff"
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
  Header always set Permissions-Policy "camera=(), microphone=(), geolocation=(), interest-cohort=()"
  Header always set Strict-Transport-Security "max-age=31536000" "expr=%{HTTPS} == 'on'"
  # Tout vient du site lui-même ; les styles en ligne restent permis (attributs style du contenu).
  Header always set Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; media-src 'self'; connect-src 'self'; form-action 'self' https://*.gongin.fr; frame-ancestors 'self'; base-uri 'self'; object-src 'none'"

  # Cache : fichiers à empreinte un an, médias un mois, pages toujours revalidées.
  <FilesMatch "\.(html|xml|txt)$">
    Header set Cache-Control "no-cache"
  </FilesMatch>
  <FilesMatch "\.(webp|png|jpg|ico|mp4|woff2)$">
    Header set Cache-Control "public, max-age=2592000"
  </FilesMatch>
</IfModule>
<IfModule mod_headers.c>
  <If "%{REQUEST_URI} =~ m#^/_astro/#">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </If>
</IfModule>

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

<IfModule mod_mime.c>
  AddType video/mp4 .mp4
  AddType font/woff2 .woff2
  AddType image/webp .webp
</IfModule>

# Site de test (EN_TEST dans src/lib/editeur.js) : aucun fichier indexé.
<IfModule mod_headers.c>
  Header always set X-Robots-Tag "noindex"
</IfModule>
