Answer the question
In order to leave comments, you need to log in
How to set up forwarding between wild-fly 8 domains?
There are two domains
- domain1.com
- domain2.com
Both point to the same wildfly-8 server address.
Is it possible to set up redirection by wildfly itself so that when going to domain1.com, the user is redirected to domain2.com?
Examples and useful links are welcome.
Answer the question
In order to leave comments, you need to log in
This is much easier to do with nginx or apache (or whatever you use to proxy requests to wildfly). Well, if you are too lazy to mess with them, then you can use such a filter in a web application:
public class HostFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
String host = httpServletRequest.getHeader("Host");
if ("domain1.com".equalsIgnoreCase(host)) {
httpServletResponse.sendRedirect("https://domain2.com" + httpServletRequest.getRequestURI() + "?" + httpServletRequest.getQueryString());
return;
}
chain.doFilter(request, response);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question