Affects: 6.2.0-M7
Issue https://github.com/spring-projects/spring-framework/issues/31366 added the new UrlHandlerFilter
. That filter should handle root URLs differently by default and not strip the trailing slash from a root URL. It seem reasonable to have a blanket UrlHandlerFilter
such as the following in your Spring application:
UrlHandlerFilter.trailingSlashHandler("/**").redirect(HttpStatus.PERMANENT_REDIRECT).build();
For example, a URL such as http://example.com/
is invalid without a trailing slash and browsers (or CURL) do in fact send a trailing slash if you do not specify it for root URLs.
See also: https://webmasters.stackexchange.com/questions/35643/is-trailing-slash-automagically-added-on-click-of-home-page-url-in-browser
Comment From: ghillert
May also be relevant for https://github.com/spring-projects/spring-framework/issues/32830
Comment From: bclozel
Thanks Gunnar for this report (and testing our milestones)!
Comment From: bdshadow
i think, the problem here is more complex.
We have:
server.servlet.contextPath=/myApp
And use the following UrlHandlerFilter
:
UrlHandlerFilter filter = UrlHandlerFilter
.trailingSlashHandler("/**").wrapRequest()
.build();
And in this case, both http://localhost:8080/myApp/items
and http://localhost:8080/myApp/items/
work fine, however,
http://localhost:8080/myApp
and http://localhost:8080/myApp/
don't and return 404.
Controller for the root looks like this:
@Controller
@RequestMapping("/")
public class MyAppUiController {
@GetMapping(value = {"/", "greeting"}, produces = MediaType.APPLICATION_JSON_VALUE)
public ModelAndView greeting() {
ModelAndView mav = new ModelAndView("greeting");
return mav;
}
}
So when you have server.servlet.contextPath
specified, it doesn't work
Comment From: bclozel
@bdshadow I don't think this is related to this particular issue. Can you create a new one with a minimal application that reproduces the problem?
Comment From: bdshadow
@bclozel thank you for your reply. Here is the issue: https://github.com/spring-projects/spring-framework/issues/33565 and a minimal app: https://github.com/bdshadow/SpringTrailingSlashTestProject