Is this while/switch actually necessary? This looks like linear code to me... it's not like any part of the URL can repeat or switch order.