# The Client Reminder - send old Bubble page links to the app subdomain.
# Email links (verify, reset_pw), payment returns etc. keep working after the root domain moves.
# Query strings are kept. 307 keeps the request method.
RewriteEngine On

# Keep the Authorization header available to PHP
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# API calls (WhatsApp webhook, Payfast notify...) are passed through to the app (see api-proxy.php)
RewriteRule ^(version-test/)?api/1\.1/ api-proxy.php [L,QSA]
RewriteRule ^(cancel|import|logo|payfast|payfast-redirect|payfast-redirect-old|verify|whatsapp|reset_pw|version-test)(/.*)?$ https://app.theclientreminder.com/$1$2 [R=307,L]

# Force https and www -> bare domain
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
