<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # 1. Route all /api/* requests to pure PHP backend
  RewriteRule ^api/(.*)$ api/index.php?_route=$1 [QSA,L]
  RewriteRule ^api$ api/index.php [QSA,L]

  # 2. If request is an existing file or directory, serve directly
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]

  # 3. Otherwise redirect all requests to index.html for React SPA Router
  RewriteRule ^ index.html [L]
</IfModule>
