# ==============================================================
#  Hôtel Résidence Jully — configuration Apache
#  Ce fichier est copié tel quel dans .output/public/ au build.
#  Il ne s'applique qu'à un hébergement Apache (cPanel, etc.).
# ==============================================================

# -- Encodage par défaut --
AddDefaultCharset UTF-8

# -- Page d'erreur --
ErrorDocument 404 /index.html

# -- Désactiver l'affichage du contenu des dossiers --
Options -Indexes

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # Forcer HTTPS
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP:X-Forwarded-Proto} !https
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # Rediriger www vers le domaine nu (décommenter si souhaité)
  # RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  # RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]

  # Fallback SPA : toute route qui ne correspond pas à un fichier
  # ou un dossier réel est servie par index.html (routage côté client).
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ index.html [L]
</IfModule>

# -- Compression (accélère le chargement) --
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
  AddOutputFilterByType DEFLATE application/javascript application/x-javascript
  AddOutputFilterByType DEFLATE application/json application/xml
  AddOutputFilterByType DEFLATE image/svg+xml application/font-woff2
</IfModule>

# -- Cache navigateur --
<IfModule mod_expires.c>
  ExpiresActive On

  # HTML : jamais mis en cache longtemps (contenu qui évolue)
  ExpiresByType text/html "access plus 0 seconds"

  # Assets versionnés (JS/CSS avec hash) : 1 an
  ExpiresByType text/css "access plus 1 year"
  ExpiresByType application/javascript "access plus 1 year"

  # Images & polices : 1 an
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType application/font-woff2 "access plus 1 year"
</IfModule>

# -- En-têtes de sécurité & de cache --
<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 "geolocation=(), microphone=(), camera=()"

  # Assets immuables (fichiers hashés du dossier assets)
  <FilesMatch "\.(?:css|js|woff2|jpg|jpeg|png|webp|svg|ico)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>

  # Ne pas mettre le HTML en cache
  <FilesMatch "\.html$">
    Header set Cache-Control "no-cache, must-revalidate"
  </FilesMatch>
</IfModule>

# -- Protéger les fichiers sensibles --
<FilesMatch "(^\.|\.(bak|config|env|ini|log|sh|sql)$)">
  Require all denied
</FilesMatch>
