开发者

Jetty RewriteHandler and RewriteRegexRule

I'm trying to rewrite a URL for a servlet. The URL gets rewritten correctly, but the context doesn't match after that. Any idea how to get this to work?

RewriteHandler rewriteHand开发者_如何学运维ler = 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");

So basically /r/asdf gets rewritten to /r?z=asdf.

However, the rewritten /r?z=asdf is now not processed by the servlet.

Also, /r?z=asdf does work if called directly.

I've pasted the full code here: http://pastebin.com/Z1isNADg


Turns out I wanted RedirectRegexRule instead of RewriteRegexRule.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜