title: Losing Session Id Every Request in Spring 3 MVC Application with Proxy by Apache
body: <p>I have a web application which I am setting up a shopping cart for; the application serves many different websites, each with it's own domain.  Virtual Hosts are used to forward each domain to the Tomcat 6 server as well as set the path to that particular websites static resources; these static resources cannot be stored in the web application, and therefore are stored on the server and served through Apache.</p>
  
  <p>first I use JkMount on my context root, then do URL rewrite with [P, L] for taking the context path "mywebapp" out of the URL, so when someone goes to this application with the domain <code>somedomain.com</code> the web application processes on <code>somedomain.com/mywebapp/store/cart</code>
  but the browser sees <code>somedomain.com/store/cart</code>.  Until now this has been working very well; The problem is that every request is having it's session reset and I don't know why.</p>
  
  <p>If I remove apache from the front end of serving the Session is not reset and works normally (as I expected).  But I can't seem to set up my virtual host to forward to the application without losing sessions.  I've read a lot about the problem but my competence is in JavaEE, and I have very little knowledge of Apache Web Server; so I'm not even sure how to begin researching the fix.</p>
  
  <p>I've heard of something called ProxyPassing but I'm not sure what that means or how it works; most examples I've seen have changes to the Tomcat server.xml adding a domain, which I can't really do because domains (virtual hosts to match) get added dynamically and I can restart Apache, but can't be restarting the JavaEE application every time a new site is added.</p>
  
  <p>Any ideas for fixing this, or getting to the root cause?  Any alternative approaches?</p>
  
  <p><strong>UDPATE</strong>:  I'm going to post my virtual host entry for one of the dynamic websites</p>
  
  <pre><code>    &lt;VirtualHost *:80&gt;
      ServerAdmin test@test.com
      DocumentRoot "C:/wamp/www"
      ServerName jawesome.com
      ServerAlias www.jawesome.com
      ErrorLog "logs/jawesome_com-error.log"
      CustomLog "logs/jawesome_com-access.log" common
  
      Alias /files/ "C:/static/1/uploaded_files/"
      &lt;Directory "C:/static/1/uploaded_files"&gt;
                  Options FollowSymLinks Indexes MultiViews
                  Order allow,deny
                  Allow from all
      &lt;/Directory&gt;
  
      JkMount /webapp ajp13
      JkMount /webapp/* ajp13
  
      RewriteEngine on
      #RewriteLogLevel 9
      #RewriteLog "/usr/local/apache/logs/testrewrite.log"
  
      RewriteCond %{REQUEST_URI} !^/(webapp/.*|files/.*)$
      RewriteRule ^/(.*)$ /webapp/$1 [P,L]
  &lt;/VirtualHost&gt;
  </code></pre>