<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

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

    # Route all non-existing files/dirs to router.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ router.php [L]
</IfModule>

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/webp "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
</IfModule>

<IfModule mod_headers.c>
    # 🔒 Disable caching for ALL dynamic routes (even ones like /home or /watch)
    <FilesMatch ".*">
        Header always set Cache-Control "no-cache, no-store, must-revalidate"
        Header always set Pragma "no-cache"
        Header always set Expires "0"
        Header always set Vary "Cookie"
    </FilesMatch>

    # ✅ Enable caching for static files
    <FilesMatch "\.(jpg|jpeg|png|webp|css|js)$">
        Header always set Cache-Control "public, max-age=2592000"
    </FilesMatch>
</IfModule>
