# ============================================================
# .htaccess — re-info.fr
# En-têtes de sécurité + suppression des extensions .html/.php
# et de "index" dans les URLs (réécriture propre, sans risque)
# À placer à la racine du site
# ============================================================

# ------------------------------------------------------------
# 1. EN-TÊTES DE SÉCURITÉ
# ------------------------------------------------------------
<IfModule mod_headers.c>

    # HSTS — force HTTPS uniquement (1 an, sous-domaines inclus)
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"

   
    Header set Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https://www.google.com; object-src 'none'; base-uri 'self'; connect-src 'self';"


    # X-Frame-Options — bloque le clickjacking
    Header always set X-Frame-Options "DENY"

    # X-Content-Type-Options — empêche le MIME sniffing
    Header always set X-Content-Type-Options "nosniff"

    # Referrer-Policy — limite les fuites d'URL d'origine
    Header always set Referrer-Policy "strict-origin-when-cross-origin"

    # Permissions-Policy — désactive caméra/micro/géolocalisation
    Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"

</IfModule>

# ------------------------------------------------------------
# 2. RÉÉCRITURE D'URL — suppression des extensions
# ------------------------------------------------------------
<IfModule mod_rewrite.c>
    RewriteEngine On

# Rediriger les scans WordPress vers le piège
RewriteRule ^wp-login\.php$ /wp-admin.php [R=302,L]
RewriteRule ^wp-admin/?$ /wp-admin.php [R=302,L]
RewriteRule ^xmlrpc\.php$ /wp-admin.php [R=302,L]
RewriteRule ^wp-content/plugins/revslider/ /wp-admin.php [R=302,L]


    # ------------------------------------------------------------
    # REDIRECTION HTTP -> HTTPS (permanente, prioritaire)
    # ------------------------------------------------------------
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # "index" -> racine (ex: /index.html ou /index -> /)
    RewriteCond %{THE_REQUEST} \s/+(index\.(html|php)|index)[\s?] [NC]
    RewriteRule ^(index\.(html|php)|index)$ / [L,R=301]

    # Suppression de l'extension .html (ex: /page.html -> /page)
    RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
    RewriteRule ^(.+)\.html$ /$1 [L,R=301]

    # Suppression de l'extension .php (ex: /contact.php -> /contact)
    RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
    RewriteRule ^(.+)\.php$ /$1 [L,R=301]

    # Réécriture interne : /page -> /page.html (si le fichier existe)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^(.+?)/?$ $1.html [L]

    # Réécriture interne : /page -> /page.php (si le fichier existe)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.+?)/?$ $1.php [L]

    # ------------------------------------------------------------
    # 3. PAGE D'ERREUR 404 personnalisée
    # ------------------------------------------------------------
    ErrorDocument 404 /404.html

</IfModule>