title: Force SSL for specific routes in Rails 3.1
body: <p>I need to force SSL on <strong>all routes</strong> in my application except for <code>landing#index</code>.</p>
  
  <p>In <code>config/application.rb</code>, I have:</p>
  
  <pre><code>config.force_ssl = true
  </code></pre>
  
  <p>Then in <code>landing_controller.rb</code>, I have:</p>
  
  <pre><code>force_ssl :except =&gt; :index
  </code></pre>
  
  <p>However, all routes are still being redirected to <code>https</code>.</p>
  
  <p>Does anyone know how to conditionally force SSL in a Rails 3.1+ application?</p>
  
  <p><strong>Solution:</strong></p>
  
  <p>Add the following to your <code>Gemfile</code>:</p>
  
  <pre><code>gem 'rack-ssl-enforcer'
  </code></pre>
  
  <p>Add the following to your <code>config/application.rb</code>:</p>
  
  <pre><code>config.middleware.use Rack::SslEnforcer, :except =&gt; [ /\/$/ ], :strict =&gt; true
  </code></pre>