Concatenating strings and dynamic resolution in 2.1

I’m trying to take the incoming domain name with www.example.com and pass it to a backend server named site.example.com. I know we can use variables now and dynamic resolution with this:

http-request do-resolve

but I’m not 100% sure how to do variable manipulation in HA proxy configuration. Does it need to be done in LUA?

This is the error I’m getting now but I’m pretty sure it’s because I’m trying to do a search and replace without do-resolve:

[ALERT] 128/124302 (66007) : parsing [haproxy.cfg:50] : 'server web-servers' : could not resolve address 'site.%[req.hdr(Host),regsub(^www.,,)]'.
[ALERT] 128/124302 (66007) : Failed to initialize server(s) addr.


global
    log         127.0.0.1 local2 debug
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    daemon
    stats socket /var/lib/haproxy/stats

resolvers mydns
  nameserver google 8.8.8.8:53
  timeout retry   1s
  hold valid 10s
  hold nx 3s
  hold other 3s
  hold obsolete 0s
  accepted_payload_size 8192

defaults
    mode                    http
    option                  httplog
    log                     global
    option                  dontlognull
    option                  http-server-close
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

frontend frontend-http

    bind *:80
    bind *:443 # ssl crt /etc/haproxy/ssl/default.pem crt /etc/haproxy/ssl

    acl redirect path_beg -i /rd
    use_backend backend-tracking if redirect

    default_backend backend-default

backend backend-default
    option forwardfor

backend backend-default
    option forwardfor
    http-response set-header X-Publishing-system website
    http-request set-header X-Target  %[req.hdr(Host)]
    http-request set-header X-Hostname %[req.hdr(Host),regsub(^www.,site.,)]
    http-request web-server do-lookup(hdr(X-Hostname))
    server web-servers  web-server:80 check

backend backend-tracking
    option forwardfor
    http-response set-header X-Publishing-system redirect
    http-request set-uri %[url,regsub(^/rd,/,)]
    server web-hp www.trackingplatform.com:80 check