2010-05-13 40 views
1

我試圖改寫爲一個servlet的URL。 URL被正確地重寫,但之後的上下文不匹配。任何想法如何讓這個工作?碼頭RewriteHandler和RewriteRegexRule

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

回答

1

原來我想RedirectRegexRule,而不是RewriteRegexRule