您可以将“/”要求转至“/lToredirect”,并由特别保护措施处理“/urlToredirect”。 类似:
public static void main(String[] args) throws Exception {
Servlet frontend = new Frontend();
Server server = new Server(8080);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.addServlet(new ServletHolder(frontend), "/index");
context.addServlet(new ServletHolder(frontend), "/auth");
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(false);
resource_handler.setResourceBase("static");
RewriteHandler rewriteHandler = new RewriteHandler();
rewriteHandler.setRewriteRequestURI(true);
rewriteHandler.setRewritePathInfo(true);
rewriteHandler.setOriginalPathAttribute("requestedPath");
RedirectRegexRule rule = new RedirectRegexRule();
rule.setRegex("/");
rule.setReplacement("/index");
rewriteHandler.addRule(rule);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]{rewriteHandler, resource_handler, context});
server.setHandler(handlers);
server.start();
server.join();
}