Redirection from Spring Boot Application of External Website

Viewed 46

I am building a Spring Boot Application with SSL enabled.

Now when I am redirecting to some external website with leading http:// explicitly. for example http://www.example.com. But browser is redirecting it to https://www.example.com automatically.

As I am not sure the target site is http or https. I want to redirect to the target as it is in my database.

Is there any one could help regarding this issue?

I have tried by returning redirect:http://www.example.com and ModelAndView approach. It did not work.

Note: My action can return html view or redirect to external site.

2 Answers

Try This :

@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public void method(HttpServletResponse httpServletResponse) {
    httpServletResponse.setHeader("Location", projectUrl);
    httpServletResponse.setStatus(302);
}

I tried by different ways from the Application. But it never worked. DevOps have added Load Balancer in the middle and something messed up while setting the Load Balancer rules. They have modified at their end. Now it's working fine.

Related