redirect from root app to app with other context in same host in tomcat

Splash Forums Rewrite Users redirect from root app to app with other context in same host in tomcat

This topic contains 5 replies, has 2 voices, and was last updated by  Serkan Durusoy 5 years, 6 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #18193

    Serkan Durusoy
    Participant

    Hi Everyone,

    I’m using Tomcat 7 and a couple of JSF2 applications.

    I have one app with context /myapp using JSF2 and prettyfaces with spring (I guess these details are not important in my case)

    I want also to deploy a ROOT app (with context /) in the same host in order to manage inbound requests that are above the /myapp path so that:

    * http://mydomain and http://mydomain/ are redirected to http://mydomain/myapp/

    * http://mydomain/xxxx and http://mydomain/xxxx/ are redirected to http://mydomain/myapp/xxxx

    My questions are as follows:

    1) Should I chose prettyfaces or rewrite for this task

    2) Given the answer to above, what would be the best configuration

    Thanks,

    Serkan

    #22216

    Serkan Durusoy
    Participant

    Quick update,

    I chose to go with rewrite since it seems to suit the job better.

    Now the question is; what should my configuration look like?

    I tried this as a quick solution:

    public class MyappConfigurationProvider extends HttpConfigurationProvider {

    @Override
    public int priority() {
    return 10;
    }

    @Override
    public Configuration getConfiguration(final ServletContext context) {
    return ConfigurationBuilder.begin()
    .defineRule()
    .when(Direction.isInbound().and(Path.matches("/{page}")))
    .perform(Redirect.temporary("/myapp/{page}"));
    }
    }

    This seems to work with http://mydomain/xxxx but not with http://mydomain

    #22217

    You path isn’t correct. Your configuration requires the path to start with a / character. Try something like:

    return ConfigurationBuilder.begin()
    .defineRule()
    .when(Direction.isInbound().and(Path.matches("{path}")
    .where("path").matches(".*")))
    .perform(Redirect.temporary("/myapp{path}"));

    I hope this helps :)

    Christian

    #22218

    Serkan Durusoy
    Participant

    Hi Christian,

    This worked like a charm.

    I need to ask a follow up question:

    * what is the priority? what does 10 mean?

    #22219

    The priority just allows to create an ordering if there are multiple implementations of HttpConfigurationProvider. If you have just on implementation this value doesn’t matter. :)

    #22220

    Serkan Durusoy
    Participant

    Oh, thanks.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Comments are closed.