Options -Indexes

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Block direct web access to CI4 internal files and directories
    RewriteRule ^(app|system|writable|tests|admin/app)(/.*)?$ - [F,L]
    RewriteRule ^(\.env|env|composer\.json|spark|preload\.php|router\.php|phpunit\.xml\.dist)$ - [F,L]

    # Let admin/ and blog/ handle their own sub-applications via their own .htaccess
    RewriteRule ^admin(/.*)?$ - [L]
    RewriteRule ^blog(/.*)?$ - [L]

    # Route application root (/ or subfolder root like /spinescopy/) to CI4 public/index.php
    RewriteRule ^$ public/index.php [L]

    # Serve existing files/directories at root directly (assets/, upload/, etc.)
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # Serve public/ static files (favicon.ico, robots.txt) safely at root or in a subfolder
    RewriteRule ^(favicon\.ico|robots\.txt)$ public/$1 [L]

    # Route everything else through CI4 public/index.php
    RewriteRule ^(.*)$ public/index.php/$1 [L,QSA]
</IfModule>
