DirectoryIndex index.php

# Disable directory browsing
Options -Indexes

<IfModule mod_rewrite.c>
    RewriteEngine On

    # If the request is an existing file or directory, serve it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # Rewrite all other requests to index.php
    RewriteRule ^ index.php [QSA,L]
</IfModule>

# Block public access to sensitive system, config, backup, and log files
<FilesMatch "(\.(env|ini|log|sql|bak|conf|git|sh|md)|error_log|composer\.(json|lock))$">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
    </IfModule>
</FilesMatch>

# 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"
</IfModule>
