May I ask, isn’t there a way at the origin host, the easier way, to create a sub-domain and move the files from the yourdomain.com/sub-directory/ to the sub-domain.yourdomain.com? - just being curious here.
I remember there was a way to do rewrites using .htaccess
I believe there is some way using Cloudflare Page Rules and Forwarding URL option, possibly.
Haven’t tried yet, cannot confirm.
Wait a bit, you have two different domains? and want to redirect from one sub-domain to other domain directory?
If so, maybe this one:
If the URL matches:
*xxxx.domain.com/*
Then the settings are:
Forwarding URL - 301 Permanent Redirect
https://www.yyyy.com/xxxx/$2
Hopefully, you would move the needed files from xxxx.com to yyyy.com/xxxx/ to make sure they exist and work.