# "/" menyajikan frontend (index.html hasil `npm run build:laravel`); bila belum ada, jatuh ke Laravel.
DirectoryIndex index.html index.php

# Folder frontend (mis. /pelanggan, /bayar) bernama sama dengan halamannya (pelanggan.html):
# jangan tambahkan "/" otomatis, biarkan aturan .html di bawah yang menanganinya.
<IfModule mod_dir.c>
    DirectorySlash Off
</IfModule>

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Handle X-XSRF-Token Header
    RewriteCond %{HTTP:x-xsrf-token} .
    RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]

    # Halaman frontend statis: /dashboard -> dashboard.html, /pelanggan/detail -> pelanggan/detail.html
    RewriteCond %{REQUEST_URI} !/$
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.+)$ $1.html [L]

    # Redirect Trailing Slashes (/dashboard/ -> /dashboard)...
    # Memakai URL asli dari browser (THE_REQUEST), bukan REQUEST_URI, karena saat project
    # dipasang di public_html request sudah di-rewrite ke /public/... oleh .htaccess root.
    RewriteCond %{THE_REQUEST} \s(/[^\s?]*?)/+(\?\S*)?\s
    RewriteRule ^ %1 [L,R=301]

    # Alamat /public/... (project di public_html) dialihkan ke alamat bersih.
    RewriteCond %{THE_REQUEST} \s/public/?([^\s?]*)[\s?] [NC]
    RewriteRule ^ /%1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

<IfModule mod_headers.c>
    # HTML frontend selalu dicek ulang agar versi baru langsung terpakai setelah upload.
    # (Cache lama untuk aset _next/static diatur di _next/static/.htaccess, dibuat oleh build:laravel.)
    <FilesMatch "\.html$">
        Header set Cache-Control "no-cache"
    </FilesMatch>
</IfModule>
