text: Q:
  
  spring mvc redirect path and all children to another domain
  
  I am trying to work out how to redirect from my webapp to another server, preserving any paths and GET vars.
  eg
  www.myapp.com/foo
  foo.com
  
  www.myapp.com/foo/bar
  foo.com/bar
  
  www.myapp.com/foo?bar=1
  foo.com?bar=1
  
  I would idealy just like to use something like
  <mvc:view-controller path="/foo/**" view-name="redirect:http://foo.com**" />
  
  A:
  
  I ended up using a filter.
  infrastructurally this seems to be the simplest way
  filter implementation:
  public class DomainRedirectFilter extends OncePerRequestFilter {
  
      private String destinationDomain;
      private String sourceServletPath;
  
      @Override
      protected void doFilterInternal(HttpServletRequest request, 
               HttpServletResponse response, FilterChain filterChain)
               throws ServletException, IOException {
          String path = request.getServletPath();
          path = StringUtils.replace(path, getSourceServletPath(), "");
          if (request.getQueryString() != null) {
              path += '?' + request.getQueryString();
          }
  
          response.setHeader( "Location", getDestinationDomain() + path );
          response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
          response.setHeader( "Connection", "close" );
      }
  
  web.xml
  <filter>
      <filter-name>fooDomainRedirectFilter</filter-name>
      <filter-class>com.abc.mvc.util.DomainRedirectFilter</filter-class>
      <init-param>
          <param-name>destinationDomain</param-name>
          <param-value>http://foo.abc.com</param-value>
      </init-param>
      <init-param>
          <param-name>sourceServletPath</param-name>
          <param-value>/foo</param-value>
      </init-param>
  </filter>
  
  <filter-mapping>
      <filter-name>fooDomainRedirectFilter</filter-name>
      <url-pattern>/foo/*</url-pattern>
      <url-pattern>/foo</url-pattern>
  </filter-mapping>
  
  I needed to add 2 url-patterns to allow for
  /foo
  /foo?id=1
  /foo/bar
  /foo/bar?id=1
  
  