RewriteEngine On

# Ensure index.php is served as directory root
DirectoryIndex index.php

# ── Security Headers ──
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-XSS-Protection "1; mode=block"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Permissions-Policy "geolocation=(self), camera=(self), microphone=()"

# ── Content Security Policy ──
# Customise as needed; this example allows inline styles/scripts (common in legacy apps)
Header always set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://*.razorpay.com https://checkout.razorpay.com https://maps.googleapis.com https://cdn.jsdelivr.net https://cdnjs.cloudflare.com; style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com https://cdn.jsdelivr.net https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com https://cdnjs.cloudflare.com; img-src 'self' data: blob: https:; connect-src 'self' https://api.razorpay.com https://api.openai.com https://graph.facebook.com https://cdn.jsdelivr.net https://cdnjs.cloudflare.com wss:; frame-src 'self' https://*.razorpay.com;"

# ── Block direct access to sensitive files ──
<FilesMatch "\.(env|json|key|log|sql|bak|sh|xml|ini|cfg|htpasswd)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>


# Portable: no hardcoded RewriteBase — works at any path
# (local /microfinance/master/admin/public, server /public, or domain root)

# If not a real file or directory, route to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]

# Font MIME types
AddType application/font-woff2 .woff2
AddType application/font-woff .woff
AddType font/ttf .ttf

