# Hostinger Apache / LiteSpeed Configuration for StudyBee
DirectoryIndex index.html index.php
Options -MultiViews

# --- SMEX FIX 1: Prevent Aggressive Browser Caching for Frontend (Bypass Old Cache) ---
<IfModule mod_headers.c>
    <FilesMatch "\.(html|htm|json)$">
        Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0"
        Header set Pragma "no-cache"
        Header set Expires 0
    </FilesMatch>
</IfModule>
# --------------------------------------------------------------------------------------

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Redirect Hostinger default placeholder page to home
RewriteRule ^default\.php$ / [R=301,L]

# Explicit routes for media, drm, and proxies to guarantee no collision
RewriteRule ^video/?$ api.php [QSA,L]
RewriteRule ^proxy/?$ api.php [QSA,L]
RewriteRule ^pdf/?$ api.php [QSA,L]
RewriteRule ^m3u8/?$ api.php [QSA,L]
RewriteRule ^mpd/?$ api.php [QSA,L]
RewriteRule ^license/?$ api.php [QSA,L]
RewriteRule ^license-proxy/?$ api.php [QSA,L]

# Route backend API and proxy requests to api.php if physical file does not exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(api|get|sex|sexy|rwa|chut|vg|login|batches|proxy)(/.*)?$ api.php [QSA,L]

# --- SMEX FIX 3: Multi-Page Clean URL Routing (Fix /content 404 issue) ---
# Agar URL bina .html ke hai (like /content ya /play), 
# aur server par wo .html file exist karti hai, toh usko silently load karo bina URL change kiye.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [QSA,L]
# -------------------------------------------------------------------------

# --- SMEX FIX 2: Frontend SPA Routing (Catch-all Fallback) ---
# Agar upar wali list me route match nahi hua, aur wo real file ya folder nahi hai, 
# toh 404 phekne ki bajaye aakhiri raste ke roop me index.html load kar do.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html [QSA,L]
# -------------------------------------------------------------

</IfModule>
