# IIS Terminal - Apache / cPanel settings
DirectoryIndex index.html
Options -Indexes

# Friendly 404 (works when the terminal sits at the domain root;
# for a sub-folder use e.g.  ErrorDocument 404 /terminal/404.html)
ErrorDocument 404 /dps/404.html

# Keep build tools, notes, the local live bridge and server config private
RedirectMatch 404 ^/?(.*/)?tools/
RedirectMatch 404 ^/?(.*/)?live/
RedirectMatch 404 ^/?(.*/)?api/_
RedirectMatch 404 ^/?(.*/)?auth/_
RedirectMatch 404 \.(md|py|bat|bak|log|ini|zip|sql|sqlite|key)$

# ---- Login gate -------------------------------------------------------
# Every page (*.html) and every data snapshot (data/*.json) goes through
# auth/gate.php, which checks the sign-in before sending it.
# The URLs stay exactly the same (index.html, stock.html?s=OGDC ...).
# Sub-folder install (e.g. /terminal/): if pages show 404, un-comment
# RewriteBase and set it to the folder; also change ErrorDocument above.
<IfModule mod_rewrite.c>
  RewriteEngine On
  # pass the mobile app's Authorization header to PHP (some cPanel/FastCGI setups drop it)
  RewriteCond %{HTTP:Authorization} .
  RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  # VTrade partner authenticate + one-time dashboard link
  RewriteRule ^api/v2/service/authenticate/?$ auth/partner_authenticate.php [L,QSA,NC]
  RewriteRule ^dashboard/?$ auth/partner_launch.php [L,QSA,NC]
  RewriteBase /dps/
  RewriteRule ^$ auth/gate.php?p=index [L,QSA]
  RewriteRule ^([a-z0-9-]+)\.html$ auth/gate.php?p=$1 [L,QSA]
  RewriteRule ^data/([A-Za-z0-9_-]+)\.json$ auth/gate.php?j=$1 [L,QSA]
</IfModule>

<IfModule mod_headers.c>
  Header always set X-Content-Type-Options "nosniff"
  Header always set Referrer-Policy "same-origin"
</IfModule>

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

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/css "access plus 7 days"
  ExpiresByType application/javascript "access plus 7 days"
  ExpiresByType image/webp "access plus 30 days"
  ExpiresByType image/png "access plus 30 days"
  ExpiresByType application/json "access plus 0 seconds"
  ExpiresByType text/html "access plus 0 seconds"
</IfModule>
