Options -Indexes
DirectoryIndex index.php

<Files "config.php">
    Order Allow,Deny
    Deny from all
</Files>

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /app-api/

    # Manejar preflight OPTIONS sin pasar por PHP
    RewriteCond %{REQUEST_METHOD} OPTIONS
    RewriteRule ^(.*)$ - [R=200,L]

    # Pasar Authorization header a PHP (necesario en cPanel CGI/FastCGI/PHP-FPM)
    # Metodo 1: via variable de entorno HTTP_AUTHORIZATION
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Metodo 2: via REDIRECT para PHP-FPM
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=REDIRECT_HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Reescribir URLs sin .php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ $1.php [L,QSA]
</IfModule>

# Pasar Authorization como variable CGI (alternativa para suPHP)
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

# Configuración adicional para cPanel PHP-FPM
<IfModule mod_setenvif.c>
    SetEnvIf Request_URI ".*" HTTP_AUTHORIZATION=%{HTTP:Authorization}
</IfModule>

# Permitir acceso a archivos PHP
<FilesMatch "\.php$">
    Order Allow,Deny
    Allow from all
</FilesMatch>
