0

I'd like to configure Spring MVC to do the following for me:

If (a controller is not found
&& controller exist for requestURI with or without trailing slash) {
    redirect 301 to other URI with or without trailing slash
} else {
    return 404 error
}

The above should be done by spring, not by some web.xml filter since only spring can test whether a redirect makes sense, i.e. whether there is a controller to handle the redirected request.

Thomas Koch
  • 2,833
  • 2
  • 28
  • 36
  • Does "a controller is not found" means that we haven't handler that is mapped on this url? – mvb13 Oct 25 '13 at 09:43
  • yes, controller is not found should say: spring would otherwise return a 404. Handler might have been the better term to use, but I'm not yet familiar with all Spring concepts. – Thomas Koch Oct 25 '13 at 11:42
  • You can find how to resolve problem with trailing slashes here http://stackoverflow.com/questions/8711392/spring-mvc-urls-with-trailing-slash-redirection and to solve problem with 404 here http://stackoverflow.com/questions/13356549/handle-error-404-with-spring-controller. To solve 404 error you should use @ExceptionHandler annotation on Controller. You should also properly configure your DispatcherServlet(It must handle urls that you need). – mvb13 Oct 25 '13 at 12:16

0 Answers0