Replaced regex in normalizeURI with a hand coded replacement method

Also, we don't rebuild the URI unless we find a problem.