Redirect rule adds colon and port number into URL

I have a rule in HAProxy (v.2.4.8) that adds a folder at the beginning of the path of certain URLs. e.g.:

http-request redirect location https://%[hdr(host)]%/folder%[path] code 301 if { path_beg /files }

This works fine, but there’s a strange glitch. If the backend the traffic is sent to a server listening on port 80, it works. If it’s sent to a server listening on port 8080, it adds in the port number, after a colon, and fails. So instead of:

I get:

I’m not sure why this is happening, or how to troubleshoot this. Is there an obvious reason, and, if not, is there an easy way of changing my rule so that it strips out any colon and port number?