# Block direct access to hidden files (.env, .env.*, etc.)
<FilesMatch "^\.">
    Require all denied
</FilesMatch>

# Also deny .env.php explicitly for extra safety
<FilesMatch "^\.env\.php$">
    Require all denied
</FilesMatch>

# Block all script/config/template files except the front controller
<FilesMatch "\.(php|json|lock|md|dist|example|yml|yaml|neon|env)$">
    <If "!%{REQUEST_URI} =~ m#/index\.php#">
        Require all denied
    </If>
</FilesMatch>

# Allow front controller explicitly
<Files "index.php">
    Require all granted
</Files>

# Deny access to config/ directory
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^config/ - [F,L]
    RewriteRule ^scripts/ - [F,L]
    RewriteRule ^system/ - [F,L]
    RewriteRule ^tests/ - [F,L]
    RewriteRule ^vendor/ - [F,L]
    RewriteRule ^storage_test_runtime/ - [F,L]
    # SEC-016: composer.json moved to project root; .dist reference is harmless
    RewriteRule ^composer\.json\.dist$ - [F,L]

    # Route all other API requests through front controller
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [QSA,L]
</IfModule>
