# VotoLibre Admin - Configuración de Seguridad Apache

# Habilitar rewrite engine
RewriteEngine On

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

# Bloquear acceso directo a carpetas sensibles
RewriteRule ^config/ - [F,L]
RewriteRule ^uploads/ - [F,L]
RewriteRule ^files/ - [F,L]

# Proteger archivos sensibles
<FilesMatch "\.(json|log|ini|env|htaccess|htpasswd)$">
    Order deny,allow
    Deny from all
</FilesMatch>

# Prevenir listado de directorios
Options -Indexes

# Headers de seguridad
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "DENY"
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https://votolibre.info;"
</IfModule>

# Configuración de caché para assets estáticos
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 month"
</IfModule>

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

# Limitar tamaño de upload (100MB)
php_value upload_max_filesize 100M
php_value post_max_size 105M
php_value max_execution_time 300
php_value max_input_time 300

# Ocultar versión de PHP
php_flag expose_php off

# Error pages personalizadas
ErrorDocument 403 /error.html
ErrorDocument 404 /error.html
ErrorDocument 500 /error.html
