from my research the whole URL thing is a minefield dues to tld, cctld, protocols and all sorts of very strange use cases that originate from the early days of the web… so it is not a simple answer.

This is how I just solved my use case in case anyone is interested.