# Enable the rewrite engine
RewriteEngine On

# === Force HTTPS Redirect ===
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# === Remove .php or .html extensions (optional) ===
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

# === Block access to sensitive backend folders ===
RewriteRule ^(src|private|node_modules|config)(/.*)?$ - [F,L]

# === Prevent directory listings ===
Options -Indexes

# === React Router fallback to index.html for SPA support ===
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [L]
