Dynamic Redirect from Subdirectory to Subdomain

I have a lot of subdomains that are mapped into the subfolders of my origin site.

I am trying to redirect https://example.com/car-insurance-city-state/ to

https://car-insurance-city-state.example.com/ with the new dynamic redirect feature.

I’ve used the concat formula concat(“https://”,http.request.uri.path,“.”,http.host,“/”) with no success, it keeps giving me a 502 bad gateway error.

Can somebody please help me with this expression?
I’ve tried modifying a previous threads expression that was posted by @eldhose eldhose(https://community.cloudflare.com/u/eldhose)

concat(“https://example.com/”, substring(http.host, 0, -12), “/”, substring(http.request.uri.path, 7))
but i do not know the length of the URL path since it is dynamic.

I’ve tried looking everywhere and there is no documentation on examples of this since its a new product.

Thank you