# Portable .htaccess for React Vite SPA hosting on Apache servers
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  
  # Protect the JSON database file from being viewed or downloaded directly in browser
  RewriteRule ^database\.json$ - [F,L]
  
  # Route /api/midtrans/token to api.php?action=midtrans_token
  RewriteRule ^api/midtrans/token$ api.php?action=midtrans_token [QSA,L]

  # Route /api/midtrans/status/(.*) to api.php?action=midtrans_status&orderId=$1
  RewriteRule ^api/midtrans/status/([^/]+)$ api.php?action=midtrans_status&orderId=$1 [QSA,L]

  # Route /api/midtrans/diagnostic to api.php?action=midtrans_diagnostic [QSA,L]
  RewriteRule ^api/midtrans/diagnostic$ api.php?action=midtrans_diagnostic [QSA,L]

  # Route /api/send-register-email to api.php?action=send_register_email
  RewriteRule ^api/send-register-email$ api.php?action=send_register_email [QSA,L]

  # Route /api/send-win-email to api.php?action=send_win_email
  RewriteRule ^api/send-win-email$ api.php?action=send_win_email [QSA,L]

  # If the requested filename exists, serve it
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  # For everything else, rewrite to index.html for React Router to handle
  RewriteRule . /index.html [L]
</IfModule>
