- you are deploying a single application as a .war file
- you need multiple root folders for your application
- you store data in HttpSession
- you have the Apache WS with mod_rewrite enabled
- Open your server.conf file in CATALINA_HOME/conf and add the following parameter to your Connector setting emptySessionPath="true". This setting will force Tomcat to use '/' as the Cookie Path for JSESSIONID, the cookie used for sessions.
- Open your httpd.conf file. First, you'll need to add additional proxy statements:
newpath is the new folder you want to setup.
applicationpath is the name of your war file
Note: I am assuming you're running apache and Tomcat on the same server. If not, replace localhost with your Tomcat host.
3. Add the following rewrite rule to your httpd.conf file
RewriteRule ^/newpath/(.*) /applicationpath/$1
4. Write your URLs correctly using the /newpath
Why this works?
You've forced tomcat to set the Session's cookie path to '/', so no matter what directories you create, your application will still receive the session cookie. The proxy statement tells Apache about the new folder to map to your application. The rewrite rule makes tomcat think that the URI is for your application.
In my next report, I'll tell you how to make sure your URLs are unique, something that is important for search engine optimization (SEO).