improve self-url discovery

(use ports if not standard, use other vars for scheme, move / around as needed)
not required for one-line if's, are they?