# Hide listings and use public/index.php by default
Options -Indexes
DirectoryIndex public/index.php

<IfModule mod_rewrite.c>
    RewriteEngine On

    # 1) Canonical redirect: if the original HTTP request asked for /public/...
    #    send a 301 to the same path without /public
    RewriteCond %{THE_REQUEST} \s/+public/ [NC]
    RewriteRule ^public/(.*)$ /$1 [R=301,L]

    # 2) Internal rewrite: for everything else, serve from /public
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
