# LIVEXWIN Clean URL Rewrites & Source Security Rules

# Block direct browser access to internal config files, JSON catalogs, SQL schemas, SQLite DBs, and docs
<FilesMatch "(^config(\.local)?\.php$|\.(json|sql|sqlite|md|txt|template|sh|bat)$)">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
    </IfModule>
</FilesMatch>

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Block direct web access to internal game_providers config directory
    RewriteRule ^(website/)?game_providers/ - [F,L]

    # Force HTTPS safely (Cloudflare/Proxy aware; skip localhost/raw IP)
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
    RewriteCond %{HTTP_HOST} !^(localhost|127\.0\.0\.1)(:\d+)?$ [NC]
    RewriteCond %{HTTP_HOST} !^\d+\.\d+\.\d+\.\d+(:\d+)?$
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Player Storefront Clean Routes (/m/index.html & /m) and Isolated Private Admin (/admin)
    RewriteRule ^m(/index\.html?)?/?$ index.php [NC,L,QSA]
    RewriteRule ^admin(/index\.php)?/?$ index.php?portal=admin [NC,L,QSA]
    RewriteRule ^sitemap\.xml$ sitemap.xml.php [NC,L]
    RewriteRule ^robots\.txt$ robots.txt.php [NC,L]

    # Seamless Wallet & <200ms API Clean Routes
    RewriteRule ^api/bigbang/wallet/user_data/?$ wallet_user.php [NC,L,QSA]
    RewriteRule ^api/bigbang/wallet/balance_change/?$ wallet_balance.php [NC,L,QSA]
    RewriteRule ^api/bigbang/callback/?$ callback.php [NC,L,QSA]
    RewriteRule ^api/bigbang/webhook/?$ webhook.php [NC,L,QSA]
    RewriteRule ^api/(balance|bet|win|webhook)/?$ api/$1.php [NC,L,QSA]

    # Hide .php extension from URLs
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>

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