<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Hidden / backup / VCS: 404 (not 403) so scanners cannot map the tree
    RewriteRule (^|/)\. - [R=404,L]
    RewriteRule \.(env|git|gitignore|gitattributes|sql|log|bak|old|swp)$ - [R=404,L]
    RewriteRule ^(vendor|composer\.(json|lock)|artisan|phpunit\.xml)(/|$) - [R=404,L]

    # Not WordPress — hard-404 scanner probes (LearnPress CVE FP, etc.) before Laravel.
    RewriteRule ^(?:wp-admin|wp-content|wp-includes|wp-json|wordpress|learnpress)(/|$) - [R=404,L,NC]
    RewriteRule ^(?:wp-login\.php|xmlrpc\.php|wp-config\.php|wp-cron\.php|wp-signup\.php|wp-trackback\.php|wp-comments-post\.php|fr-login\.php|backend\.php)$ - [R=404,L,NC]

    # Deny PHP execution under uploaded/public storage paths
    RewriteRule ^storage/.*\.ph(p[0-9]?|tml|ar|ps)$ - [F,L]
    RewriteRule ^uploads/.*\.ph(p[0-9]?|tml|ar|ps)$ - [F,L]

    # Deny direct HTTP access to uploaded legal PDFs (must use DocumentFileController)
    RewriteRule ^storage/uploads/documents(/|$) - [F,L]
    RewriteRule ^storage/uploads/puu-publications(/|$) - [F,L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Handle X-XSRF-Token Header
    RewriteCond %{HTTP:x-xsrf-token} .
    RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
