1

Have spring boot 1.3.x application with server.context-path=/mypath defined in application.properties and also redirecting requests as defined in Java Spring Boot: How to map my app root (“/”) to index.html?

Requests with url example.com/mypath map to example.com/mypath/index.html using viewControllerRegistry.addViewController("/").setViewName("forward:/index.html")

Also need requests with url example.com/ to be automatically redirected to example.com/mypath

Is this possible with a server.context-path=/mypath defined? Would prefer to have Spring Boot do the redirect rather than having to introduce nginx or apache httpd, but don't see how to make this happen. Investigated removing the context-path, but it would result in too many changes to a well established large code base.

Community
  • 1
  • 1
R. Allen
  • 11
  • 2

3 Answers3

0

Maybe there is a better solution, but you could map the application to example.com (don't set the server.context-path) and create a controller listening to the base URL and redirecting all your requests to example.com/mypath, having all your other controllers mapped to example.com/maypath/somecontroller1, example.com/maypath/somecontroller2 and so on.

Thomas Schmidt
  • 1,248
  • 2
  • 12
  • 37
0

Redirect was implemented with nginx

R. Allen
  • 11
  • 2
-1

Not sure if there are other easy ways to do it with spring-boot but in past I have used tuckey rewrite filter - http://tuckey.org/urlrewrite/

itwarilal
  • 1,314
  • 1
  • 10
  • 17