Replace one domain (url) to the other

Hello, how to make Haproxy replace Location
there is a domain
https://test.com/login
I want clinet to get the same after entering https://localhost/login
but backend verifies that the match must be test.com

i do
http-request replace-value Location %[hdr(host)]/(.)$ https://test.com\1
http-response replace-value Location ^https://test.com/(.
)$ %[hdr(host)]/\1

but i have loop