# <IfModule mod_rewrite.c>
#     <IfModule mod_negotiation.c>
#         Options -MultiViews -Indexes
#     </IfModule>

#     RewriteEngine On

#     # Handle Authorization Header
#     RewriteCond %{HTTP:Authorization} .
#     RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

#     # Handle X-XSRF-Token Header
#     RewriteCond %{HTTP:x-xsrf-token} .
#     RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]

#     # Redirect Trailing Slashes If Not A Folder...
#     RewriteCond %{REQUEST_FILENAME} !-d
#     RewriteCond %{REQUEST_URI} (.+)/$
#     RewriteRule ^ %1 [L,R=301]

#     # Send Requests To Front Controller...
#     RewriteCond %{REQUEST_FILENAME} !-d
#     RewriteCond %{REQUEST_FILENAME} !-f
#     RewriteRule ^ index.php [L]
# </IfModule>

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        # Empêche lister le contenu des dossiers et MultiViews
        Options -MultiViews -Indexes
    </IfModule>

    # Active la réécriture d'URL
    RewriteEngine On

    # Handle Authorization Header
    # Cette règle est CRITIQUE pour que Apache préserve le header Authorization
    # qui est souvent supprimé par défaut par Apache
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Préserver la méthode HTTP (PUT, DELETE, etc.)
    # Certains serveurs/proxies convertissent ces méthodes en GET
    # Cette règle tente de préserver la méthode originale
    RewriteCond %{REQUEST_METHOD} ^(PUT|DELETE|PATCH)$
    RewriteRule .* - [E=REQUEST_METHOD:%{REQUEST_METHOD}]

    # Si le fichier ou dossier demandé existe, Apache le sert directement
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f

    # Sinon, toutes les requêtes sont envoyées à index.php
    RewriteRule ^ index.php [L]
</IfModule>

# Fallback au cas où mod_rewrite ne fonctionne pas
DirectoryIndex index.php

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php82” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php82 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
