25
Spring MVC (3.0) considers URLs with and without trailing slashes as the same URL.
For example:
http://www.example.org/data/something = http://www.example.org/data/something/
I need to redirect the URL with trailing slashes
to the URL without it:
I need to do this internally the application (so not rewrite rules via Apache, etc).
A way to do it is:
@ResponseStatus(value=HttpStatus.MOVED_PERMANENTLY)
@RequestMapping(value = "/data/something/")
public String dataSomethingRedirect(...) {
return "redirect:/data/something";
}
but this has generally 2 problems:
- too many controllers
- problem with parameters: like wrong encoding
Question
Is there a way to intercept all the URLs and in case they have a trailing slash, redirect them to the relative one without slash?