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

# ---------------------------------------------------------------------
# Never serve dotfiles, logs, database files, backups or archives from
# the document root. Without this, a stray php_errors.log or a database
# dump copied into public/ is downloadable by anyone, leaking absolute
# server paths, stack traces and - in the case of the SQLite file -
# every password hash in the system.
# ---------------------------------------------------------------------
<FilesMatch "(^\.|\.(log|sql|sqlite|sqlite3|db|bak|old|orig|save|swp|swo|ini|env|yml|yaml|json|lock|zip|tar|gz|tgz|bz2|7z|rar|md5|sha1)$)">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
    </IfModule>
</FilesMatch>

# Block direct access to dot-prefixed files (.env, .git, .htaccess itself).
<FilesMatch "^\.">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
    </IfModule>
</FilesMatch>

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
