RewriteEngine On
DirectorySlash Off

# Redirect Cpv1 to Cpv2
RewriteRule ^(.*)/whmcssmarters(.*)$ $1/smarterspro$2 [R=301,L]

# Redirect to dns.php when the URL contains /?/Android
RewriteCond %{QUERY_STRING} ^/Android$
RewriteRule ^$ dns.php [L]

# Ensure both /api/dns and /api/dns.php are handled correctly
RewriteRule ^api/dns(\.php)?$ dns.php [QSA,L]

# Handle default Windows call
RewriteRule ^api/windns(\.html)?$ dns.php [QSA,L]

# Handle other API routes (both with and without .php)
RewriteRule ^api/api(\.php)?$ api.php [QSA,L]
RewriteRule ^api/home(\.php)?$ home.php [QSA,L]
RewriteRule ^api/player_api(\.php)?$ player_api.php [QSA,L]
RewriteRule ^api/rate(\.php)?$ rate.php [QSA,L]
RewriteRule ^api/response_api(\.php)?$ response_api.php [QSA,L]
RewriteRule ^api/update(\.php)?$ update.php [QSA,L]
RewriteRule ^api/vpn(\.php)?$ vpn.php [QSA,L]

# Handle remaining API routes that require special parameters
RewriteRule ^api/ads(\.php)?$ ads.php?ad-type=webview [L]
RewriteRule ^api/adview(\.php)?$ ads.php?ad-type=webview [L]
RewriteRule ^api/combo(\.php)?$ ads.php?ad-type=webview [L]
RewriteRule ^api/autoads(\.php)?$ ads.php?ad-type=webview [L]
RewriteRule ^api/menads(\.php)?$ ads.php?ad-type=webview [L]

#RewriteRule ^api/sport(\.php)?$ webview.php?fetch=sport [L]
RewriteRule ^api/sports(\.php)?$ webview.php?fetch=sport [L]
#RewriteRule ^api/sport_top(\.php)?$ webview.php?fetch=sport_top [NC,L]
#RewriteRule ^api/sport_tv_today(\.php)?$ webview.php?fetch=sport_tv_today [NC,L]

# Handle other special routes
RewriteRule ^api/intro(\.php)?$ images.php?type=intro [L]
RewriteRule ^api/backdrop(\.php)?$ webview.php?fetch=background_alt [L]

# OpenVPN Routes
RewriteRule ^ovpnfile\.txt$ ovpnfile.php [L]
RewriteRule ^ovpn\.zip$ vpn.php [L]
RewriteRule ^vpncertificate\.zip$ vpn.php [L]

# Sports Routes
RewriteRule ^sport(\.php)?$ webview.php?fetch=sport [NC,L]
RewriteRule ^sports(\.php)?$ webview.php?fetch=sport [NC,L]
RewriteRule ^sport_top(\.php)?$ webview.php?fetch=sport_top [NC,L]
RewriteRule ^sport_tv_today(\.php)?$ webview.php?fetch=sport_tv_today [NC,L]

# Other Routes
RewriteRule ^intro(\.php)?$ images.php?type=intro [L]
RewriteRule ^backdrop(\.php)?$ webview.php?fetch=background_alt [L]

# Image Routes
RewriteRule ^logo/bg(\.php)?$ images.php?type=logo [L]
RewriteRule ^Background/bg(\.php)?$ images.php?type=bg [L]

# Extra Ad Pages
RewriteRule ^adpage(\.php)?$ ads.php?ad-type=webview [L]
RewriteRule ^adview(\.php)?$ ads.php?ad-type=webview [L]
RewriteRule ^ads(\.php)?$ ads.php?ad-type=webview [L]
RewriteRule ^api(\.php)?\?type=vod$ ads.php [L]
RewriteRule ^api(\.php)?\?type=series$ ads.php [L]
RewriteRule ^response(\.php)?(\?action=alldata)?$ ads.php [L]
RewriteRule ^adview(\.php)?$ ads.php?ad-type=webview [L]
RewriteRule ^combo(\.php)?$ ads.php?ad-type=webview [L]
RewriteRule ^autoads(\.php)?$ ads.php?ad-type=webview [L]
RewriteRule ^menads(\.php)?$ ads.php?ad-type=webview [L]

# AndyHax stuff
RewriteRule ^discover(\.php)?$ graphql.php [L]

# Remove need for .php extension (applicable globally)
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
