Options -Indexes
Options -MultiViews

RewriteEngine On

# Force HTTPS (uncomment in production)
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Allow direct access to real files and directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

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

# Security headers
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "SAMEORIGIN"
    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=(self), camera=(), microphone=()"
</IfModule>

# Cache static assets
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg          "access plus 1 month"
    ExpiresByType image/png           "access plus 1 month"
    ExpiresByType image/webp          "access plus 1 month"
    ExpiresByType image/svg+xml       "access plus 1 month"
    ExpiresByType image/x-icon        "access plus 1 year"
    ExpiresByType text/css            "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType application/manifest+json "access plus 1 day"
</IfModule>

# Compress text files
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/javascript application/json
</IfModule>

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

# Protect config directory
<IfModule mod_rewrite.c>
    RewriteRule ^config/ - [F,L]
    RewriteRule ^app/ - [F,L]
    RewriteRule ^database/ - [F,L]
</IfModule>

# PHP settings (shared hosting)
<IfModule mod_php.c>
    php_value upload_max_filesize 10M
    php_value post_max_size 12M
    php_value max_execution_time 60
    php_value memory_limit 128M
    php_flag display_errors Off
    php_flag log_errors On
</IfModule>
