Jetty RewriteHandler and RewriteRegexRule
Posted
by Justin
on Stack Overflow
See other posts from Stack Overflow
or by Justin
Published on 2010-05-13T05:19:43Z
Indexed on
2010/05/13
5:24 UTC
Read the original article
Hit count: 318
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.
© Stack Overflow or respective owner