문제

I'm using Ocpsoft Rewrite, to perform URL rewriting in a JSF project. I have a redirect rule, which works fine:

.addRule()
        .when(Direction.isInbound().and(Path.matches("/venue/{id}")))
        .perform(Redirect.temporary(context.getContextPath() + 
                "/protected/index.xhtml?venueID={id}"));

However, because of the redirect, this changes the URL in the navigation bar. I thought I could use a Join rule instead, but it doesn't work as i expected:

.addRule(Join.path("/venue/{venueID}").to("/protected/index.xhtml"))
        .perform(Log.message(Level.INFO, "Rewrite is active!"));

I thought this rule would redirect from, for example, foo/venue/123 to foo/protected/index.xhtml?venueID=123, but I don't get the ?venueID=... parameter appended to the URL.

Anyone knows what the correct rule should look like?

도움이 되었습니까?

해결책

Your rule looks correct. But a Join doesn't result in a redirect. Instead it forwards the request internally. This means that the URL isn't changed. So you won't "see" the parameter venueID in the URL. But you will be able to read the parameter using the standard Servlet API:

String id = HttpServletRequest.getParameter("venueID");

다른 팁

If you really want, you can do a Forward instead:

.addRule()
.when(Direction.isInbound().and(Path.matches("/venue/{id}")))
.perform(Forward.to("/protected/index.xhtml?venueID={id}"));

But this won't handle outbound HTML link correction like Join will!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top