# UpSync Louvor — front controller (document root = public/)
Require all granted

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

    RewriteEngine On

    # HTTPS obrigatório quando FORCE_HTTPS=1 estiver definido no ambiente do servidor (ou descomente as 2 linhas abaixo).
    # RewriteCond %{HTTPS} !=on
    # RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Cabeçalho Authorization (API) e X-XSRF-Token
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteCond %{HTTP:x-xsrf-token} .
    RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]

    # Remove barra final de URLs que não são pastas
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Envia tudo para o front controller
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

# Assets compilados: cache longo (nomes com hash)
<IfModule mod_headers.c>
    <FilesMatch "\.(js|css|woff2|png|webp|svg)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>
    <FilesMatch "^(sw\.js|manifest\.webmanifest)$">
        Header set Cache-Control "no-cache"
    </FilesMatch>
</IfModule>
