"rewrite URLs that don`t match any servlet or files"
Why not just have a Error handler on status code 404 instead?
This is the easiest approach.
Make it return whatever you want, rewrite it, etc...
Alternatively, if you don't rely on welcome files, you could map your welcome files to a servlet name.
That way it runs if the incoming path doesn't match a servlet, and not a directly mentioned static file name.
Make your servlet do what you need.
Option 3 is to provide your own DefaultServlet behavior (mapped to `<url-pattern>/</url-pattern>`.
Lets call this MyDefaultServlet.
If you get called, then you'll know that you have matched no Servlets.
Then it's just a matter of returning the static file (if it exists), or rewriting the URL it that doesn't match.
Check out the code for DefaultServlet, you'll essentially want to have a different doGet()
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
if(!_resourceService.doGet(request,response))
{
// didn't serve a static file, do your special logic here.
response.sendRedirect("/other/path/that/I/want/to/rewrite/to");
}
}