Jetty RewriteHandler 和 RewriteRegexRule

发布于 2024-09-01 17:08:59 字数 991 浏览 5 评论 0原文

我正在尝试重写 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我偏爱纯白色 2024-09-08 17:08:59

结果我想要 RedirectRegexRule 而不是 RewriteRegexRule

Turns out I wanted RedirectRegexRule instead of RewriteRegexRule.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文