RewriteEngine On

Options -Indexes

# Skip all rewrites for admin panel & mobile API (they handle their own rules)
RewriteCond %{REQUEST_URI} ^/account/adm/ [NC]
RewriteRule ^ - [L]

# Redirect explicit index.php requests to neat /account/ URL (browser bar only, NOT AJAX)
RewriteCond %{HTTP:X-Requested-With} !^XMLHttpRequest$ [NC]
RewriteCond %{THE_REQUEST} \s+/account/index\.php[\s\?]
RewriteRule ^index\.php$ /account/ [R=301,L]

# Redirect other PHP files to extensionless URLs (browser bar only, NOT AJAX)
RewriteCond %{HTTP:X-Requested-With} !^XMLHttpRequest$ [NC]
RewriteCond %{THE_REQUEST} \s+/account/([^\s]+)\.php[\s\?]
RewriteRule ^(.+)\.php$ /account/$1 [R=301,L]

# Allow extensionless access to PHP files (e.g., /account/help, AJAX /account/otp-status)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L,QSA]

DirectoryIndex index.php
