# =====================================================================
# Xitel Links — konfigurasi Apache (cPanel)
# =====================================================================
Options -Indexes
DirectoryIndex index.html

<IfModule mod_rewrite.c>
  RewriteEngine On

  # --- Paksa HTTPS (hapus tanda # di 3 baris berikut SETELAH SSL aktif) ---
  # RewriteCond %{HTTPS} off
  # RewriteCond %{HTTP:X-Forwarded-Proto} !https
  # RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # Folder app/ (config, sesi, data) tidak boleh diakses dari browser
  RewriteRule ^app(/|$) - [F,L]

  # Semua /api/... diarahkan ke api/index.php
  RewriteRule ^api(/.*)?$ api/index.php [L,QSA]
</IfModule>

# Tipe file PWA
<IfModule mod_mime.c>
  AddType application/manifest+json .webmanifest
  AddType text/javascript .js
</IfModule>
<Files "manifest.json">
  ForceType application/manifest+json
</Files>

<IfModule mod_headers.c>
  Header always set X-Content-Type-Options "nosniff"
  Header always set X-Frame-Options "DENY"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
  Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
  <FilesMatch "\.(html|js|css|json|png)$">
    Header set Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self'; manifest-src 'self'; worker-src 'self'; frame-ancestors 'none'; base-uri 'self'; form-action 'self'"
  </FilesMatch>
  <FilesMatch "\.(html|json)$|^sw\.js$">
    Header set Cache-Control "no-cache"
  </FilesMatch>
  <FilesMatch "\.(css|js|png)$">
    Header set Cache-Control "public, max-age=3600"
  </FilesMatch>
  <Files "sw.js">
    Header set Cache-Control "no-cache"
  </Files>
</IfModule>

# Blokir file sensitif
<FilesMatch "(^\.|\.(sql|sqlite|log|md|bak)$)">
  <IfModule mod_authz_core.c>
    Require all denied
  </IfModule>
  <IfModule !mod_authz_core.c>
    Order allow,deny
    Deny from all
  </IfModule>
</FilesMatch>
