The gist of it is that if you have https:// and http:// and www.domain.com and domain.com google sees 4 versions of you site. It will pick one of them as the main site each time it ranks your site. This can change every, effecting the ranking, as it looks like duplicated content.
For Sinatra there is a nice bit of middle were called rack-no-www which adds the redirect for you.
Add to you gem file
gem "rack-no-www", "~> 0.0.2", :require => 'rack/no-www'
gem install rack-no-www
Usage in a basic Sinatra App (app.rb)
require 'sinatra' require 'rack/no-www' use Rack::NoWWW get '/' do 'Helloworld' end
ruby app.rb With web browser view localhost:4567. If that is working then you should find www.localhost:4567 redirects back to localhost:4567