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

    RewriteEngine On

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

    # Handle X-XSRF-Token Header
    RewriteCond %{HTTP:x-xsrf-token} .
    RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]

    # Redirect Trailing Slashes If Not A Folder...
    # (except /landing/ and its sub-folders: the landing page needs the slash for its relative links)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/landing/
    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>

# --- Speed (Apache, e.g. XAMPP): compress text, let browsers keep files that never change ---
# Each block only runs when its Apache module is on; without them the site works the same.
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/xml application/javascript text/javascript application/json image/svg+xml application/manifest+json
</IfModule>

<IfModule mod_headers.c>
    # Built files have their content hash in the name (theme-XXXX.css): safe to keep a year.
    <If "%{REQUEST_URI} =~ m#/build/assets/#">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </If>
    # Uploaded pictures (new ones get new names) and theme images, fonts, icons.
    <If "%{REQUEST_URI} =~ m#/(storage|themes)/#">
        Header set Cache-Control "public, max-age=2592000"
    </If>
</IfModule>

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/webp "access plus 30 days"
    ExpiresByType image/png "access plus 30 days"
    ExpiresByType image/jpeg "access plus 30 days"
    ExpiresByType image/svg+xml "access plus 30 days"
    ExpiresByType font/woff2 "access plus 1 year"
    # Pages are never kept: prices, stock and carts change.
    ExpiresByType text/html "access plus 0 seconds"
</IfModule>
