Jetty RewriteHandler 和 RewriteRegexRule
我正在尝试重写 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
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 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");
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果我想要
RedirectRegexRule
而不是RewriteRegexRule
。Turns out I wanted
RedirectRegexRule
instead ofRewriteRegexRule
.