# Amul Investment Platform - Main .htaccess
# Strict routing for frontend/backend separation

RewriteEngine On
RewriteBase /

# ===== CRITICAL: Protect dist folder files from rewriting =====
# These MUST be served directly, never rewritten to index.html
RewriteRule ^dist/.*\.js$ - [L]
RewriteRule ^dist/.*\.css$ - [L]
RewriteRule ^dist/.*\.json$ - [L]
RewriteRule ^dist/ - [L]

# ===== Protect specific directories =====
RewriteRule ^backend(/|$) - [L]
RewriteRule ^install(/|$) - [L]

# ===== Protect API paths =====
RewriteRule ^api(/|$) - [L]

# ===== Never rewrite actual files =====
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# ===== Never rewrite actual directories =====
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# ===== Route everything else to index.html for Angular SPA =====
RewriteRule . index.html [QSA,L]

# ===== MIME type corrections =====
<IfModule mod_mime.c>
    AddType text/css .css
    AddType application/javascript .js
    AddType application/json .json
    AddType image/svg+xml .svg
    AddType font/woff2 .woff2
    AddType font/woff .woff
</IfModule>

# ===== Force correct MIME types =====
<FilesMatch "\.js$">
    AddType application/javascript .js
    Header set Content-Type "application/javascript; charset=utf-8"
</FilesMatch>

<FilesMatch "\.css$">
    AddType text/css .css
    Header set Content-Type "text/css; charset=utf-8"
</FilesMatch>

# ===== Security headers =====
<IfModule mod_headers.c>
    Header set X-UA-Compatible "IE=edge"
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set X-XSS-Protection "1; mode=block"
</IfModule>

# ===== Gzip compression =====
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css application/javascript
</IfModule>

# ===== Cache control =====
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 day"
    ExpiresByType text/html "access plus 0 seconds"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType image/* "access plus 1 year"
    ExpiresByType font/* "access plus 1 year"
</IfModule>


