1

Let's say I need to map requests which don't have . to add a suffix for them, for example:

/a
/a/b
/a/b/c

but not

/a.html
/a/b.html
/a/b/c.html

I am able to map it with a a particular level, with something like the below, but that means a new mapping for each level, and I don't think this is the correct way.

I tried to use /** but then how to handle the values which I am not interested it (e.g. the ones with .?

@Controller
public class HtmlController {

  @RequestMapping("/{page:^[^.]*$}")
  public String oneLevel(@PathVariable("page") String page) {
    return '/' + page + ".html";
  }

  @RequestMapping("/{first}/{page:^[^.]*$}")
  public String twoLevels(@PathVariable("first") String first, @PathVariable("page") String page) {
    return '/' + first + '/' + page + ".html";
  }

 ...
}

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56

1 Answers1

0

I suggest you to use an interceptor that extends HandlerInterceptorAdapter and in the preHandle method of it, you can reject all the requests which contain '.' in their URLs

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Azadi Yazdani
  • 246
  • 1
  • 9
  • Thanks, but it isn't about rejecting the requests, but rather change the location of some of the requests. In other words, I don't think in `preHandle` one can change the request URI. – Ahmed Ashour Jun 20 '23 at 11:33