Options -Indexes -MultiViews
DirectoryIndex index.php

<IfModule mod_rewrite.c>
    RewriteEngine On

    # If the project root is accidentally configured as the document root,
    # block direct requests into private source and runtime directories.
    RewriteCond %{DOCUMENT_ROOT}/.env -f [OR]
    RewriteCond %{DOCUMENT_ROOT}/app -d [OR]
    RewriteCond %{DOCUMENT_ROOT}/vendor -d
    RewriteRule ^(?:\.git|\.github|app|bootstrap|config|database|docs|install|resources|routes|storage|vendor|cpanel-public-root|tests|public)(?:/|$) - [F,L,NC]

    # Refuse document roots that point into private application/runtime trees.
    # The supported in-project document root is exactly the application's public/ directory.
    RewriteCond %{DOCUMENT_ROOT} /(?:app|bootstrap|config|database|install|storage|vendor|framework|sessions|cache|views|logs|private)(?:/|$) [NC]
    RewriteCond %{DOCUMENT_ROOT} !/public$ [NC]
    RewriteRule ^ - [F,L]

    # Preserve authorization and XSRF headers for Laravel.
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteCond %{HTTP:X-XSRF-TOKEN} .
    RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-TOKEN}]

    # Route non-file and non-directory requests through Laravel.
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

<FilesMatch "(?i)(^\.|composer\.(json|lock)$|^artisan$|^phpunit\.xml$|\.(sql|log|bak|old)$)">
    Require all denied
</FilesMatch>

<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "DENY"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>
