I am learning Apache .htaccess configuration. I would like to apply https to a URL if domain is mydomain.com only if URI stars from API and followed by digits Example--> "http://exampledomain.com/api/123456" to be redirected to https://exampledomain.com/index.php?val=123456 in backend server.
I have tried the below but it isn't working. I have not been able to get the API link also to properly rewrite. Any help would be highly appreciated.
RewriteEngine On
RewriteRule ^api/([0-9]+) index.php?val=$1 [NC,L]
RewriteCond %{HTTP_HOST} ~exampledomain.com [NC]
RewriteRule (.*) https://%{HTTP_HOST}$1 [R,NC]