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


    RewriteEngine On

    # 1. Redirect /public/anything to /anything (301 Permanent Redirect)
    RewriteCond %{THE_REQUEST} \s/+public(?:/([^\s\?]*))?\s [NC]
    RewriteRule ^ /%1 [L,R=301]

    # 2. Prevent direct access to sensitive files
    RewriteRule ^(\.env|\.git|composer\.(json|lock)|package\.(json|lock)|artisan) - [F,L,NC]

    # 3. Route all traffic to the /public directory
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>


