Pregunta

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?

¿Fue útil?

Solución

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");

Otros consejos

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!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top