
# Enable Rewrite Engine
RewriteEngine On

# Set RewriteBase if in subdirectory (uncomment and adjust if needed)
# RewriteBase /inventory-system/

# Skip rewriting for existing files and directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Prevent direct access to PHP files
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^admin/.*\.php$ - [F,L]

# Error Documents
ErrorDocument 404 /404.php
ErrorDocument 403 /403.php

# Index
RewriteRule ^index$ index.php [L,QSA]

# Dashboard
RewriteRule ^admin/dashboard$ dashboard.php [L,QSA]

# Authentication
RewriteRule ^login$ login.php [L,QSA]
RewriteRule ^logout$ logout.php [L,QSA]

# Profile
RewriteRule ^profile/edit$ profile/edit_profile.php [L,QSA]
RewriteRule ^profile/change-password$ profile/change_password.php [L,QSA]
RewriteRule ^profile/notifications$ profile/notifications_all.php [L,QSA]

# Materials (วัสดุ)
RewriteRule ^admin/materials$ admin/materials_list.php [L,QSA]
RewriteRule ^admin/materials/deleted$ admin/materials_deleted_list.php [L,QSA]
RewriteRule ^admin/material/add$ admin/material_add.php [L,QSA]
RewriteCond %{QUERY_STRING} !id=
RewriteRule ^admin/material/edit/([0-9]+)$ admin/material_edit.php?id=$1 [L,QSA]
RewriteRule ^admin/material/edit/[^0-9]+ - [R=404,L]
RewriteRule ^admin/material/delete/([0-9]+)$ admin/material_delete.php?id=$1 [L,QSA]

