Options -Indexes
DirectoryIndex index.php
ServerSignature Off

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

# Isolate this app's PHP session when Apache runs mod_php.
# PHP-FPM/CGI receives the same settings from .user.ini.
<IfModule mod_php.c>
    php_value session.name MTRPHAPSESSID
    php_flag session.use_strict_mode On
    php_flag session.use_only_cookies On
    php_flag session.cookie_httponly On
    php_value memory_limit 256M
    php_value upload_max_filesize 20M
    php_value post_max_size 24M
</IfModule>
<IfModule mod_php8.c>
    php_value session.name MTRPHAPSESSID
    php_flag session.use_strict_mode On
    php_flag session.use_only_cookies On
    php_flag session.cookie_httponly On
    php_value memory_limit 256M
    php_value upload_max_filesize 20M
    php_value post_max_size 24M
</IfModule>

<IfModule mod_authz_core.c>
    <FilesMatch "(^\.|\.env$|composer\.(json|lock)$|package(-lock)?\.json$|phpunit\.xml$|.*\.md$|EXAMPLE_.*\.php$)">
        Require all denied
    </FilesMatch>
    <FilesMatch "\.(ini|cnf|bak|log|sql|sqlite|zip|tar|gz|rar|7z|map|ps1|sh|cmd|bat)$">
        Require all denied
    </FilesMatch>
</IfModule>

<IfModule !mod_authz_core.c>
    <FilesMatch "(^\.|\.env$|composer\.(json|lock)$|package(-lock)?\.json$|phpunit\.xml$|.*\.md$|EXAMPLE_.*\.php$)">
        Order allow,deny
        Deny from all
    </FilesMatch>
    <FilesMatch "\.(ini|cnf|bak|log|sql|sqlite|zip|tar|gz|rar|7z|map|ps1|sh|cmd|bat)$">
        Order allow,deny
        Deny from all
    </FilesMatch>
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^install(?:\.php)?/?$ install.php [END,NC]
    RewriteRule ^setup(?:\.php)?/?$ setup.php [END,NC]

    # Operational endpoints bypass the HTML dispatcher so health can report a
    # database outage. Both endpoints enforce their own strong secrets/policy.
    RewriteRule ^health(?:\.php)?/?$ health.php [END,NC]
    RewriteRule ^cron(?:\.php)?/?$ cron.php [END,NC]

    # Validated SVG bytes only; raw uploads remain blocked by sitelogo/.htaccess.
    RewriteRule ^branding-image(?:\.php)?/?$ branding-image.php [END,NC]

    # The physical exness directory must not win over the application
    # dispatcher; its asset files remain directly addressable below it.
    RewriteRule ^exness/?$ route.php?route=exness [QSA,END,NC]

    # Only extensionless, allow-listed classic admin routes reach the dispatcher.
    # Legacy PHP, uploads, assets, and snapshots inside adminold remain private.
    RewriteRule ^adminold/?$ route.php?route=adminold [QSA,END,NC]
    RewriteRule ^adminold/([a-z0-9-]+)/?$ route.php?route=adminold/$1 [QSA,END,NC]
    RewriteRule ^adminold(?:/|$) - [F,L,NC]

    # Source/runtime folders belong to this repository, not the public web surface.
    RewriteRule ^(\.agents|\.claude|\.codex|\.git|\.github|\.playwright-cli|\.playwright-mcp|\.vscode|adminold_backup[^/]*|config|database|docs|frontend|frontend-next|includes|kycimage|kyc_images|node_modules|output|scripts|storage|templates|test-results|tests|tmp|vendor)(/|$) - [F,L,NC]

    # Avoid mod_dir exposing the internal dispatcher query when /admin is
    # requested without a trailing slash.
    RewriteCond %{THE_REQUEST} \s([^?\ ]*)/admin/?(?:[?\ ]|$) [NC]
    RewriteRule ^admin/?$ %1/admin/login [R=302,L,NE]

    # Keep the legacy comparison panel addressable beside the native admin.
    RewriteCond %{THE_REQUEST} \s([^?\ ]*)/admin1/?(?:[?\ ]|$) [NC]
    RewriteRule ^admin1/?$ %1/admin1/login [R=302,L,NE]

    # Admin2 is a compatibility URL surface backed by the hardened admin1
    # adapters; it must enter the same route/authentication dispatcher.
    RewriteCond %{THE_REQUEST} \s([^?\ ]*)/admin2/?(?:[?\ ]|$) [NC]
    RewriteRule ^admin2/?$ %1/admin2/login [R=302,L,NE]

    # Static assets/uploads stay public. PHP pages and clean URLs use the legacy dispatcher.
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteCond %{REQUEST_URI} !\.php$ [NC]
    RewriteRule ^ - [L]

    # Subfolder-safe legacy routing stays inside this project.
    RewriteRule ^$ index.php [L]
    RewriteRule ^(.+)$ route.php?route=$1 [QSA,L]
</IfModule>

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 7 days"
    ExpiresByType application/javascript "access plus 7 days"
    ExpiresByType text/javascript "access plus 7 days"
    ExpiresByType image/png "access plus 30 days"
    ExpiresByType image/jpeg "access plus 30 days"
    ExpiresByType image/webp "access plus 30 days"
    ExpiresByType image/svg+xml "access plus 30 days"
    ExpiresByType font/woff2 "access plus 30 days"
</IfModule>

<IfModule mod_headers.c>
    Header always unset X-Powered-By
    Header always set X-Content-Type-Options "nosniff"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=()"

    # Build artifacts are content-hashed, so they can be cached permanently.
    <FilesMatch "(?i)-[a-z0-9]{6,}\.(?:css|js)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>
    <Files "manifest.json">
        Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
    </Files>
</IfModule>

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain text/html text/css text/javascript
    AddOutputFilterByType DEFLATE application/javascript application/json application/xml
    AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php8_module>
   php_flag log_errors On
</IfModule>
<IfModule lsapi_module>
   php_flag log_errors On
</IfModule>
# END cPanel-generated php ini directives, do not edit
