Separate rewrite rules for two virtual host apps running on same tomcat server

Splash Forums Rewrite Users Separate rewrite rules for two virtual host apps running on same tomcat server

This topic contains 12 replies, has 2 voices, and was last updated by  eframsergio 46 minutes ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #27521

    eframsergio
    Participant

    I started working on a single web application and was able to implement the desire rewrite rules and everything worked fine.

    I’m now launching a second web application with a new set of rewrite rules, but want to run them both on the same tomcat server as virtual hosts.

    So I setup both virtual hosts and they are running correctly. However, only the first app seems to be applying the rewrite rules correctly, while the second ignores them.

    Does this mean that the rewrite configuration runs at the server level and not on each individual hosts? Is is possible to have two different rewrite configurations, one on each virtual host web app?

    Thanks in advance!

    • This topic was modified 1 week, 1 day ago by  eframsergio.
    #27523

    No, the rules are per web application. So maybe there is something wrong with your rules?

    #27524

    eframsergio
    Participant

    That’s great to know!

    I will start debugging my code!

    Thanks!!!

    #27525

    eframsergio
    Participant

    Just a quick comment… I’m seeing some strange behavior.

    I noticed that I need to have this setting in the <Host> section of the server.xml configuration file in order for rewrite to work correctly on my second app.

    <Context docBase=”my-second-app” path=”/my-second-app” reloadable=”true” source=”org.eclipse.jst.jee.server:my-second-app”/>

    Does this make any sense? And why does this only affect my second app, but not the first one?

    Thanks in advance!

    #27526

    I’m not sure why this configuration should affect whether Rewrite works or not. Why do you think so? It basically just configures the context root and the location of your app.

    #27527

    eframsergio
    Participant

    To be honest, I don’t remember adding that specific line. I was playing with the virtual host configuration context for my new two apps and I know I entered the docBase and path, but not the source property. So eclipse/tomcat must have added that.

    Anyway, while I was cleaning the configuration, I came across those two lines (one for each virtual host) and deleted them and all of the sudden my debug messages (ie. .perform(Log.message(Level.INFO, “Client requested path: {path}”))) were no longer output to the console from either app. However, the rewrite configuration was working on the first app, but not the second one. So for instance, http://localhost/my-second-app/ would no longer forward to http://localhost/my-second-app/index.xhtml

    So after re-inserting those two previous config lines, log messages from both apps would now output to console and the second app would correctly forward to start page.

    I’m glad is working now, but I only found the solution by pure chance! I would have never thought of adding those context lines to my host configurations.

    What do you make of all this?

    Thanks in advance!

    #27528

    I guess if you remove those lines, the webapp isn’t deployed at all. So it will not be just Rewrite which stops working. But that’s just a guess.

    #27531

    eframsergio
    Participant

    Just to make sure, I tasted it again a few minutes ago…

    When I comment out the line:

    <Context docBase=”my-second-app” path=”/my-second-app” reloadable=”true” source=”org.eclipse.jst.jee.server:my-second-app”/>

    in the server.xml file, the second app’s rewrite rules will NOT Redirect from http://localhost/my-second-app/ to http://localhost/my-second-app/index.xhtml and I get this error.

    
    HTTP Status 404 - The requested resource is not available.

    The first app’s rewrite rules work regardless of whether or not a similar context property is set.

    Finally, when I uncomment the said Context property, the rewrite rule for second app works correctly.

    Strange indeed… I still haven’t figure out how to set this property in the production server because each app runs an a separate host as root and require a different setup, but working on it…

    Thanks!

    • This reply was modified 3 days, 6 hours ago by  eframsergio.
    #27533

    If you remove the Context element, do the unrewritten resources of your web app work at all?

    #27534

    eframsergio
    Participant

    Yes it does!

    The app works perfectly, except my URLs aren’t pretty, I have to write out the full page names (ie. start.xhtml) when the Context element is commented out. It’s a JPA/JSF-based app.

    PS: Using Rewrite-2.0.12 by the way.

    Thanks!
    sb

    • This reply was modified 2 days, 6 hours ago by  eframsergio.
    • This reply was modified 2 days, 6 hours ago by  eframsergio.
    #27537

    eframsergio
    Participant

    Hey Christian, I kept on troubleshooting and what seemed to fix the issue, at least in my local dev server, was to undeploy and redeploy both apps.

    I now have to test it on the production server and see if it works as well…

    Will post my results here…

    Thanks!

    #27538

    It is difficult to tell what is wrong in your case. My suggestion is to increase the log level to see if Rewrite starts up or not.

    #27539

    eframsergio
    Participant

    Hey, just wanted to let you know that the issues went away after I redeployed the app. A resource must have gotten tied up in there, so it was pretty difficult to solve the issue while it was in that state…

    Thanks for the help!!!

    sb

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

You must be logged in to reply to this topic.

Comments are closed.