RewriteEngine On

# 1) Canonical URLs: strip trailing slash (except bare root) — 301 for SEO.
RewriteCond %{REQUEST_URI} ^/.+/$
RewriteRule ^(.+)/$ /$1 [R=301,L]

# 2) Serve pre-rendered static cache file directly, bypassing PHP entirely.
RewriteCond %{DOCUMENT_ROOT}/cache/$1/index.html -f
RewriteRule ^(.*)$ /cache/$1/index.html [L]

# 3) Serve real files/directories as-is (css, cache assets, etc.).
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# 4) Everything else goes through the front controller.
RewriteRule ^ index.php [L]
