# Laravel shared-hosting entry point.
# Keep the domain document root pointed at this project directory.
Options -Indexes -MultiViews
DirectoryIndex index.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Redirect legacy /index.php/... URLs to clean URLs.
    # THE_REQUEST prevents redirect loops after the internal front-controller rewrite.
    RewriteCond %{THE_REQUEST} \s/+index\.php(?:[/\s?]) [NC]
    RewriteRule ^index\.php(?:/(.*))?$ /$1 [R=301,L,NE]

    # Never expose dotfiles or Laravel source directories.
    RewriteRule (^|/)\.(?!well-known/) - [F,L]
    RewriteRule ^(app|bootstrap|config|database|resources|routes|storage|tests|vendor)(/|$) - [F,L,NC]
    RewriteRule ^(artisan|composer\.(json|lock)|phpunit\.xml|server\.php|\.env.*)$ - [F,L,NC]

    # Serve public assets from /public while keeping clean browser URLs.
    RewriteCond %{REQUEST_URI} !^/public/ [NC]
    RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f
    RewriteRule ^(.+)$ public/$1 [L]

    # Let Apache serve real files/directories in the project root.
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # Send application routes to Laravel's root entry point.
    RewriteRule ^ index.php [L,QSA]
</IfModule>
