When individuals access my application on www.example.com and sign in, they obtain a cookie. I am while using cookie choice to store session on Rails. Being able to access example.com (with no www), they have to sign in again, because Opera doesn't recognize the prior session.

So, what is your opinion is the easiest method to avoid this?

I suppose I'll make use of a small .htaccess rule (Apache + Passenger) such as this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]

Do everyone think that's a great choice?

Things I would do is:

  1. Setup separate virtual hosts for domain.com and www.domain.com
  2. Never publish links to domain.com, simply to www.domain.com
  3. Whenever a user agent demands http://domain.com/, redirect having a 301 reaction to http://www.domain.com/
  4. Only problem snacks from www.domain.com
  5. Create result in the whole site offered by domain.com, only the primary page (that is rerouted)

You don't have to involve rails within this solution whatsoever.

Create separate virtual host entry:

ServerName domain.com
Redirect permanent / http://www.domain.com

The redirect points the consumer for your other virtual host:

ServerName www.domain.com