Haproxy url rewrite and masking

Then find out why, by checking your backend logs.

This configuration does exactly what you requested:

Client request:

GET /test/foo HTTP/1.1
Host: testhost
User-Agent: curl/7.48.0
Accept: /

Request recieved at the backend server from haproxy:

GET /newtest/foo HTTP/1.1
Host: testhost
User-Agent: curl/7.48.0
Accept: /
X-Forwarded-For: 10.0.0.4