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

    RewriteEngine On

    # If /public is requested while the web root already points to public, redirect it away.
    RewriteCond %{THE_REQUEST} \s/+public/?([^\s?]*) [NC]
    RewriteRule ^public/?(.*)$ /$1 [R=301,L,NE]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

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

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

<IfModule mod_headers.c>
    # Theme files use explicit version query strings; a one-week browser cache is safe
    # without marking mutable, non-fingerprinted files immutable.
    <FilesMatch "\.(?:css|js|woff2?|ttf|eot)$">
        Header set Cache-Control "public, max-age=604800"
    </FilesMatch>

    # Uploaded images can be replaced, so keep their cache lifetime deliberately shorter.
    <FilesMatch "\.(?:gif|jpe?g|png|webp|avif|ico)$">
        Header set Cache-Control "public, max-age=86400"
    </FilesMatch>
</IfModule>

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript application/json application/xml image/svg+xml
</IfModule>
