code: public static String rewriteURI(String uri, HttpHost targetHost) {
          try {
              return URIUtils.rewriteURI(createURI(uri), targetHost).toString();
          } catch (URISyntaxException e) {
              throw new InvalidUriException(e);
          }
      }
docs: Replaces the scheme, host and port in a URI.
  
  @param uri
  the URI
  @param targetHost
  the target host
  @return the rewritten URI