RewriteEngine On

# Redirect to HTTPS (uncomment in production)
# RewriteCond %{HTTPS} !=on
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Block access to sensitive directories
RewriteRule ^(config|core|database|logs)/ - [F,L]

# Don't rewrite existing files/directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Route all requests through index.php
RewriteRule ^(.*)$ index.php [QSA,L]

# Security headers
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set X-XSS-Protection "1; mode=block"
    Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# Disable directory listing
Options -Indexes

# Protect .env and sensitive files
<FilesMatch "\.(env|sql|log|ini|sh|bak)$">
    Order allow,deny
    Deny from all
</FilesMatch>
