开发者

Jetty RewriteHandler and RewriteRegexRule

开发者 https://www.devze.com 2022-12-30 07:17 出处:网络
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?

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

精彩评论

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