# Root .htaccess for https://crypto.codeblux.com/data/
Options -Indexes

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Force HTTPS in production (skip on localhost)
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^localhost [NC]
    RewriteCond %{HTTP_HOST} !^127\.0\.0\.1
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Pass Authorization header to PHP under CGI/FastCGI on cPanel
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Block direct web access to private folders
    RewriteRule ^(config|shared|storage)(/|$) - [F,L]
    RewriteRule ^api/controllers(/|$) - [F,L]

    # Allow Admin panel under /data/ceo/system/admin/ to run directly
    RewriteRule ^ceo/system/admin(/|$) - [L]

    # Stop if already routed to api/index.php
    RewriteRule ^api/index\.php$ - [L]

    # Route all API endpoints (/data/app-config, /data/auth/*, etc.) to api/index.php
    RewriteRule ^ api/index.php [QSA,L]
</IfModule>

<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "DENY"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>
