RewriteEngine On

# Redirect to login if not authenticated
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/login.php
RewriteCond %{REQUEST_URI} !^/assets/
RewriteCond %{HTTP_COOKIE} !PHPSESSID=[^;]+
RewriteRule ^(.*)$ /login.php [R=302,L]

# Pretty URLs
RewriteRule ^dashboard$ dashboard.php [L]
RewriteRule ^pengguna$ modules/pengguna/index.php [L]
RewriteRule ^pengguna/tambah$ modules/pengguna/tambah.php [L]
RewriteRule ^pengguna/edit/([0-9]+)$ modules/pengguna/edit.php?id=$1 [L]
RewriteRule ^asal-usul$ modules/asal-usul/index.php [L]
RewriteRule ^jenis-barang$ modules/jenis-barang/index.php [L]
RewriteRule ^lokasi$ modules/lokasi/index.php [L]
RewriteRule ^inventaris$ modules/inventaris/index.php [L]
RewriteRule ^inventaris/tambah$ modules/inventaris/tambah.php [L]
RewriteRule ^inventaris/edit/([0-9]+)$ modules/inventaris/edit.php?id=$1 [L]
RewriteRule ^inventaris/cetak$ modules/inventaris/cetak.php [L]