# Keep sessions while switching domains

**URL:** <https://www.ruby-forum.com/t/keep-sessions-while-switching-domains/114645>\
**Category:** Rails\
**Created:** [September 17, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/keep-sessions-while-switching-domains/114645 "2007-09-17T13:23:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![migo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f14d63/32.png) [@migo](https://www.ruby-forum.com/u/migo)\
**Post date:** [September 17, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/keep-sessions-while-switching-domains/114645/1 "2007-09-17T13:23:34Z")

</div>

Hello,

Our rails app has several domains. We are now implementing a single  
https connection [https://secure.domain.xx](https://secure.domain.xx).  
All other domains need to switch to that new secure domain in certain  
circumstances.  
We only have one ssl cert and it is not possible to create and use a  
ssl cert for all domains!

Now when switching domains we loose the session, that was previously  
used and I was not able to restore my old session.  
I was trying to send the old session id via the url and then reuse it  
by setting it again like this:

redirect\_to :host =\> ‘127.0.0.1:3000’ , :session\_key =\>  
request.cookies[‘\_xxx\_session\_id’][0] unless (request.env[‘HTTP\_HOST’]  
== ‘127.0.0.1:3000’)

cookies[:\_xxx\_session\_id] = params[:session\_key]

This failed since rails seems to regenerate a new session id somehow  
at a later stage. The new session cookie will have this newly  
generated id.

How can I tell Rails to use my session id ?  
Has anybody an idea on how to do this? I must get the old session  
transferred to the new domain in order to access the session data.

Many thanks in advance for any help on this.  
migo
