We don't want to assign a path directly to url.pathname that contains a search query, since this causes '?' at the beginning of the query to be URL-encoded to '%3F'. Instead use URL() to parse the path for us.