Proper escaping of URLs when replacing query parameter