I have a spring MVC application which is hosted on a server S. All the calls from a client C goes to S via loadbalancer L. The url that load balancer uses internally for server S is internalurl.com and the url that client uses is xyz.com.
The issue, is when I hit a url say xyz.com/admin/ on my mozilla browser, I expect it to get redirected to xyz.com/admin/home.html. But instead, it is redirecting to internalurl.com/admin/home.html and since internalurl.com is internal to load-balancer, I get "Network Access Message: The website cannot be found" on my browser with "internalurl.com/admin/home.html" in my browser addressbar
For redirection, I am using :
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
String strReferer = request.getHeader("Referer");
String strConetextPath = request.getContextPath();
if (strReferer != null && !strReferer.contains(strConetextPath)) {
response.sendRedirect("/requestError.html");
}
// redirect to home.html in case user tries to access /admin/
// in case user is not already logged-in, user will be redirected to login.html
else if (request.getRequestURI().equalsIgnoreCase("/admin/")) {
response.sendRedirect("home.html");
}else
chain.doFilter(req, res);
}
Thanks in advance.