# PDPrint - Configurações Apache
# Versão: 1.0

# Habilitar Rewrite Engine
RewriteEngine On

# Redirecionar para HTTPS (descomente se tiver SSL)
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Redirecionar www para não-www (ou vice-versa)
# RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
# RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Proteger arquivos sensíveis
<Files "*.sql">
    Order allow,deny
    Deny from all
</Files>

<Files "*.log">
    Order allow,deny
    Deny from all
</Files>

<Files "*.md">
    Order allow,deny
    Deny from all
</Files>

<Files ".env">
    Order allow,deny
    Deny from all
</Files>

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

# Proteger pasta includes
<Directory "includes">
    Order allow,deny
    Deny from all
</Directory>

# Configurações de segurança
<IfModule mod_headers.c>
    # Prevenir XSS
    Header always set X-Content-Type-Options nosniff
    Header always set X-Frame-Options DENY
    Header always set X-XSS-Protection "1; mode=block"
    
    # Política de referrer
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    
    # Cache para arquivos estáticos
    <FilesMatch "\.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$">
        Header set Cache-Control "public, max-age=31536000"
    </FilesMatch>
</IfModule>

# Compressão GZIP
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

# Configurações PHP
<IfModule mod_php7.c>
    php_value upload_max_filesize 32M
    php_value post_max_size 32M
    php_value memory_limit 256M
    php_value max_execution_time 300
    php_value max_input_vars 3000
</IfModule>

<IfModule mod_php8.c>
    php_value upload_max_filesize 32M
    php_value post_max_size 32M
    php_value memory_limit 256M
    php_value max_execution_time 300
    php_value max_input_vars 3000
</IfModule>

# Páginas de erro personalizadas
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php

# Prevenir acesso direto a arquivos PHP em certas pastas
<FilesMatch "^(config|functions|classes)\.php$">
    Order allow,deny
    Deny from all
</FilesMatch>

# Bloquear bots maliciosos
<Limit GET POST>
    order allow,deny
    deny from 46.161.9.
    deny from 91.200.12.
    allow from all
</Limit>

# Prevenir hotlinking de imagens
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?seudominio\.com\.br [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [F]

