# ===========================================
# 📌 ROOT HTACCESS (FINAL FIXED)
# ===========================================

# Redirect otomatis ke login.php
DirectoryIndex login.php index.php

# Mencegah list isi folder
Options -Indexes

# Aktifkan mod_rewrite
RewriteEngine On
RewriteBase /

# Redirect domain utama ke halaman login di folder system-absent
RewriteCond %{HTTP_HOST} ^(www\.)?ideaproper\.my\.id$ [NC]
RewriteRule ^$ /system-absent/login.php [L,R=302]

# ===========================================
# 🧩 Friendly URL Root (tanpa .php)
# ===========================================
# Contoh: /login → login.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

# ===========================================
# 🔒 Lindungi file sensitif
# ===========================================
<FilesMatch "(\.env|composer\.json|composer\.lock|config\.php|db\.php)">
    Require all denied
</FilesMatch>

# ===========================================
# ⚠️ Custom Error Pages
# ===========================================
ErrorDocument 403 /system-absent/public/errors/403.php
ErrorDocument 404 /system-absent/public/errors/404.php

# ===========================================
# 🚪 FRIENDLY URL UNTUK LOGIN DAN LOGOUT
# ===========================================
# /login → /system-absent/login.php
RewriteRule ^login$ /system-absent/login.php [L,QSA]

# /logout → /system-absent/logout.php
RewriteRule ^logout$ /system-absent/logout.php [L,QSA]
