Encode path component and query string key