<IfModule mod_rewrite.c>
    RewriteEngine On

    # Prevent loop if already rewritten to public/
    RewriteCond %{REQUEST_URI} ^/public/ [NC]
    RewriteRule ^ - [L]

    # If the file exists directly in root (e.g. install.php, favicon.ico), serve it directly
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # Rewrite all other requests to public/
    RewriteRule ^$ public/ [L]
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
