<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /api/

    # Allow CORS Preflight
    RewriteCond %{REQUEST_METHOD} OPTIONS
    RewriteRule ^(.*)$ config.php [QSA,L]

    # Auth
    RewriteRule ^auth/login$ login.php [QSA,L]

    # Admin
    RewriteRule ^admin/students(/batch|/update|/delete)?$ admin_students.php [QSA,L]
    RewriteRule ^admin/exams/toggle$ admin_exams.php [QSA,L]
    RewriteRule ^admin/exams/delete$ admin_exams.php [QSA,L]
    RewriteRule ^admin/exams/([0-9]+)/questions$ admin_questions.php?exam_id=$1 [QSA,L]
    RewriteRule ^admin/exams$ admin_exams.php [QSA,L]
    RewriteRule ^admin/questions(/batch|/clear-all|/delete)?$ admin_questions.php [QSA,L]
    RewriteRule ^admin/results(/delete|/clear)?$ admin_results.php [QSA,L]
    RewriteRule ^admin/cheat-logs(/clear)?$ admin_cheats.php [QSA,L]
    RewriteRule ^admin/rapor(/batch|/delete|/sync-exams)?$ admin_rapor.php [QSA,L]

    # Siswa
    RewriteRule ^siswa/exams/([0-9]+)/questions$ siswa_questions.php?exam_id=$1 [QSA,L]
    RewriteRule ^siswa/exams/start$ siswa_start.php [QSA,L]
    RewriteRule ^siswa/exams/submit$ siswa_submit.php [QSA,L]
    RewriteRule ^siswa/exams$ siswa_exams.php [QSA,L]
    RewriteRule ^siswa/my-results$ siswa_results.php [QSA,L]
    RewriteRule ^siswa/cheat-log$ siswa_cheat.php [QSA,L]
    RewriteRule ^siswa/rapor$ siswa_rapor.php [QSA,L]
</IfModule>
