I need to rewrite my URLs according to the following pattern: cloud.example.com/<application>?query becomes: <application>.cloud.example.com/main?query
HAProxy will terminate SSL - I have a wildcard certificate for *.cloud.example.com. As the target servers are running Docker Enterprise, I do not need DNS entries for every possible instance of <application> as Docker EE will handle this internally. Is there a way to do this?

