RewriteEngine On

# Redirect everything to index.php (front controller pattern)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]

# Security: Deny access to sensitive files
<FilesMatch "^\.">
    Deny from all
</FilesMatch>

<FilesMatch "(composer\.json|composer\.lock|\.env)">
    Deny from all
</FilesMatch>

# Security headers
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "DENY"
    Header set X-XSS-Protection "1; mode=block"
</IfModule>

# CORS is handled entirely by the PHP CorsMiddleware.
# Do NOT add CORS headers here to avoid duplicate/conflicting headers.

# Handle OPTIONS preflight requests by passing to PHP middleware
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ index.php [QSA,L]

# PHP settings
<IfModule mod_php.c>
    php_value upload_max_filesize 10M
    php_value post_max_size 10M
    php_value max_execution_time 300
</IfModule>