# ==============================================================================
# CORPINTECH MASTER FRAMEWORK HTACCESS
# ==============================================================================

# 1. CORE ENGINE
RewriteEngine On
RewriteBase /

# 2. FAST-TRACK STATIC ASSETS (Crucial for your 0.6s JS fix)
# This ensures images, css, and js are served instantly without PHP intervention
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# 3. GLOBAL ROUTING (Off-branch Logic)
# Redirect /page to /page/ for SEO consistency
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ $1/ [R=301,L]

# 4. API & SYSTEM REWRITES (Off-branch Logic)
# Maps tracking requests and API calls
RewriteRule ^api/(.*)$ sys/api/index.php [L,QSA]
RewriteRule ^gnotr/(.*)$ resource/tracking.js [L,QSA]

# 5. DYNAMIC PAGE ROUTING (The Merge)
# Property/Product IDs (CRM focus)
RewriteRule ^property/([^/]+)/$ index.php?page=property&prop_id=$1 [L,QSA]

# Standard Pages
RewriteRule ^([^/]+)/$ index.php?page=$1 [L,QSA]

# 6. ERROR HANDLING
ErrorDocument 404 /index.php?page=404

# 7. PERFORMANCE & SECURITY (Main Branch Logic)
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/javascript application/json
</IfModule>

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
</IfModule>

<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "DENY"
</IfModule>

# Prevent directory listing
Options -Indexes