<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# 1. Bypass CORS (Penting untuk H2H dan Fetch Aplikasi)
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS"
Header set Access-Control-Allow-Headers "Content-Type, Authorization, Accept"
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]

# 2. Routing API ke PHP Murni (Tanpa HTML/JS)
RewriteRule ^produk/([^/]+)/?$ produk.php?apikey=$1 [QSA,L]

# Route untuk Status Transaksi
RewriteRule ^status/([^/]+)/([^/]+)/?$ gateway.php?action=status&apikey=$1&trx=$2 [QSA,L]

# Route untuk Eksekusi Transaksi (Reguler & Bebas Nominal)
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ gateway.php?action=trx&apikey=$1&kode=$2&tujuan=$3&trx=$4&server=$5 [QSA,L]

</IfModule>

# =================================================================
# 3. ATURAN ANTI-CACHE (DITAMBAHKAN)
# Memaksa Browser dan Service Worker selalu meminta file baru ke Server
# =================================================================
<IfModule mod_headers.c>
    # Berlaku untuk file HTML, PHP, JavaScript (termasuk sw.js), CSS, dan JSON
    <FilesMatch "\.(html|htm|php|js|css|json)$">
        Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0"
        Header set Pragma "no-cache"
        Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
    </FilesMatch>
</IfModule>