# Mini App routing / index fallback
DirectoryIndex index.html index.php
Options -Indexes

<IfModule mime_module>
    AddHandler application/x-httpd-ea-php81 .php
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /telegram-bot/public/mini_app/

    # Never rewrite API endpoints or real files/directories
    RewriteRule ^api/ - [L]
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # If Telegram opens /mini_app without slash or any frontend route, show index
    RewriteRule ^ index.html [L]
</IfModule>

# v27.32: prevent Telegram/WebView from keeping stale Mini App HTML during hotfixes
<IfModule mod_headers.c>
    <FilesMatch "^index\.html$">
        Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
        Header set Pragma "no-cache"
        Header set Expires "0"
    </FilesMatch>
</IfModule>
