Use host to fill in variables in a rule?

Is there a way of using certain portions of a host and injecting them back into a rule? For example, I have this rule:

http-request redirect location https://sub.domain1.tld1/folder/domain2.tld2 code 301 if { hdr(host) -i sub.domain2.tld2 }

Can I pull the sub from the host and place it in the sub in the location, the domain2 from the host and place it into the domain2 in the location, and the tld2 from the host and place it into the tld2 in the location?

Thanks!