code: public static String concatenateForRewrite(
        final String base,
        final String encodedPath,
        @Nullable final String encodedQueryString
    )
    {
      // Query string and path are already encoded, no need for anything fancy beyond string concatenation.
  
      final StringBuilder url = new StringBuilder(base).append(encodedPath);
  
      if (encodedQueryString != null) {
        url.append("?").append(encodedQueryString);
      }
  
      return url.toString();
    }
docs: Concatenate URI parts, in a way that is useful for proxy servlets.
  
  @param base               base part of the uri, like http://example.com (no trailing slash)
  @param encodedPath        encoded path, like you would get from HttpServletRequest's getRequestURI
  @param encodedQueryString encoded query string, like you would get from HttpServletRequest's getQueryString