# ============================================================
# FRESIL C.A. — Sistema de Inventario
# Configuración Apache (.htaccess)
# ============================================================

Options -Indexes -ExecCGI
ServerSignature Off

# ── Rewrite Engine ──────────────────────────────────────────
RewriteEngine On

# Forzar HTTPS (activar en producción con SSL)
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# ── API: Rutas limpias (opcional) ───────────────────────────
RewriteRule ^api/auth/login$   api/auth/login.php   [L,QSA]
RewriteRule ^api/auth/logout$  api/auth/logout.php  [L,QSA]
RewriteRule ^api/auth/refresh$ api/auth/refresh.php [L,QSA]
RewriteRule ^api/auth/me$      api/auth/me.php      [L,QSA]
RewriteRule ^api/usuarios$     api/usuarios/index.php [L,QSA]

# ── Seguridad: Headers ──────────────────────────────────────
<IfModule mod_headers.c>
    Header always set X-Frame-Options "DENY"
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set Permissions-Policy "geolocation=(), microphone=(), camera=(self)"
    # Activar en producción con HTTPS:
    # Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"

    # Ocultar versión PHP
    Header unset X-Powered-By
</IfModule>

# ── Proteger archivos sensibles ──────────────────────────────
<FilesMatch "^(config|classes|middleware)/">
    Order Allow,Deny
    Deny from all
</FilesMatch>

<FilesMatch "\.(sql|log|env|bak|git|sh)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# ── PHP: Configuración de seguridad ──────────────────────────
<IfModule mod_php.c>
    php_flag expose_php Off
    php_value upload_max_filesize 10M
    php_value post_max_size 12M
    php_value max_execution_time 30
    php_value memory_limit 128M
</IfModule>

# ── Caché de assets estáticos ────────────────────────────────
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css             "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType image/png            "access plus 1 month"
    ExpiresByType image/jpeg           "access plus 1 month"
</IfModule>

# ── Compresión GZIP ──────────────────────────────────────────
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json
</IfModule>
