Question: Setting SESSION Cookie Paths in Apache Tomcat

One of the developers here has been hunting for a solution to the following configuration issue:

In tomcat, a SESSION's cookie path is automatically generated by Tomcat and set to the application's context path (e.g., the name of the .war file). This creates somewhat of an issue as it forces all URLs of the application to live underneath this folder. The issue is that the application is now getting URLs that are three, four, and even five levels deep. Long URLs are generally bad for SEO (search engine optimization), so it would be great if we could eliminate the application context's urls and have several root folder aliases that point to the same application.

This can easily be done with Apache's mod-rewrite, but the SESSION cookie path is the lingering issue. If the application name is 'foo', then the session cookie's path will be set to '/foo'. If I create new urls that live in a different root folder, say '/bah' and use Apache re-write to translate them to '/foo', then the mapping works and the correct pages fire, but the SESSION cookie won't be included in the browser's request since it lives in the '/foo' path.

Ideally, I should be able to set the SESSION cookie's path to the root folder '/'. This would not create an issue for us since we only have one other application running, the default one, that handles static objects. Ideally, I'd rather not use our application as the default.

So if anyone has a solution to this issue, feel free to comment!

Thanks!

2 comments:

  1. Yep. What you want is for the cookies to all have a path of "/".

    If you are using Tomcat, go to the conf/server.xml file, find the Connector tag, and add this to the Connector tag's list of attributes:

    emptySessionPath="true"

    ReplyDelete
  2. Thanks Michael. It took me a while, but I eventually found this solution and it works like a charm.

    I published the solution here:
    http://ctotodevelopers.blogspot.com/2006/11/how-to-tomcat-applications-with.html

    as part of a larger solution of configuring Tomcat for multiple folders

    ReplyDelete

Comments on this blog are moderated and we do not accept comments that have links to other websites.

Share

About Isaac Sacolick

Isaac Sacolick is President of StarCIO, a technology leadership company that guides organizations on building digital transformation core competencies. He is the author of Digital Trailblazer and the Amazon bestseller Driving Digital and speaks about agile planning, devops, data science, product management, and other digital transformation best practices. Sacolick is a recognized top social CIO, a digital transformation influencer, and has over 900 articles published at InfoWorld, CIO.com, his blog Social, Agile, and Transformation, and other sites. You can find him sharing new insights @NYIke on Twitter, his Driving Digital Standup YouTube channel, or during the Coffee with Digital Trailblazers.