Excluding specific subdirectories or API paths from global Apache .htaccess URL rewrite rules prevents unwanted redirection loops.

.htaccess Mod_Rewrite Rules

.htaccessapache
RewriteEngine On
 
# Exclude /api/ and /static/ directories from global HTTPS redirect rule
RewriteCond %{REQUEST_URI} !^/(api|static)/ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=308,L]