Jetty RewriteHandler和RewriteRegexRule

时间:2010-05-13 05:19:43

标签: java regex jetty mod-rewrite embedded-jetty

我正在尝试重写servlet的URL。 URL被正确重写,但在此之后上下文不匹配。知道如何让这个工作吗?

RewriteHandler rewriteHandler = new RewriteHandler();
rewriteHandler.setRewriteRequestURI(true);
rewriteHandler.setRewritePathInfo(true);
rewriteHandler.setOriginalPathAttribute("requestedPath");

RewriteRegexRule rewriteRegexRule = new RewriteRegexRule();
rewriteRegexRule.setRegex("/r/([^/]*).*");
rewriteRegexRule.setReplacement("/r?z=$1");
rewriteHandler.addRule(rewriteRegexRule);

ContextHandlerCollection contextHandlerCollection = new ContextHandlerCollection();
Context servletContext = new Context(contextHandlerCollection, "/");

servletContext.addServlet(new ServletHolder(new RedirectServlet()), "/r");

所以基本上/r/asdf会被重写为/r?z=asdf

但是,重写的/r?z=asdf现在不由servlet处理。

此外,/r?z=asdf如果直接调用也可以。

我在这里粘贴了完整的代码:http://pastebin.com/Z1isNADg

1 个答案:

答案 0 :(得分:1)

原来我希望RedirectRegexRule代替RewriteRegexRule