I am using Spring annotations with boot.
Currently, i'm handling static content in the following way:
@RequestMapping("/{path:[^\\.]*}")
public String getResourceFile(@PathVariable("path") String path) {
return path + ".html";
}
That way, if one access mysite.com/login, he will get login.html file.
Note: I do know one can configure spring to handle static content rather than implement a controller method, however I was unable to achieve the above result, no matter the configuration.
Anyhow, my current problem is I don't want users to actually reach the .html files. That is, I want the above to still work, AND any user trying to reach *.html file will get an error (not found).
I thought about implementing a controller method for *.html files (regex pattern matching), However they also trigger when I try to forward the url from the controller file, as mentioned above.
How can I achieve this then?
EDIT
Also, I would love to know how I can redirect from a controller, to a not-controller (even if it matches). That way, I'll be able to create a controller for all paths. Note currently, I only handle one url 'level'; That is, the url mysite.com/data/login will not match. And I can't use **, since it will then be recursive. That is, i'm looking for something like the following:
@RequestMapping("/**")
public String getResource(HttpServletRequest request) {
String path = request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
// Following is WRONG.
// It will call this function over and over again, resulting
// in path.html.html.html ..
return path + ".html"; // WRONG
}