1
votes

I have a Spring Boot application in which the context path is the following:

server.servlet.context-path=/data

I have a controller that supposed to redirect everyone that visits the contextpath url:

@RequestMapping("/")
public String contextRootRedirect(){
    return "redirect:/main";
}

This works fine on the localhost, whenever I visit 127.0.0.1:8080/data I am being redirected to 127.0.0.1:8080/data/main However if I run this on the server then http://domainname.com/data redirects me to http://localhost:8080/data/main

How can I make sure the redirects work on the domain name as well?

1
Is there by any chance a proxy in front of the server? If yes it should set the FORWARDED-FOR etc. headers so Spring can use those to construct a proper URL. - M. Deinum

1 Answers

0
votes

If your application server is behind a web server, this problem is likely caused by your web server configuration. This issue can be resolved by using the following entry in the httpd.conf or apache2.conf file:

ProxyRequests Off
ProxyPreserveHost On

<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>