Redirect Logic + Link reformatting based on referring domain?

I am trying to figure out if I can dynamically format my redirect link based on a value in the referring domain. I’m out of my wheelhouse and I’m not sure where to start with this.

Use Case: I have a series of affiliate links referring customers to a signup page. Each link is structured as follows: www.domain.com/signup/refering_code. When a customer signs up, the referring code is captured and the referring domain gets a commission.

I am wondering if I can create a forwarding link that dynamically forwards and reformats the incoming links like: www.new--domain.com/signup?code={reffering_code}

Is this a use case that works for redirecting/forwarding traffic?