Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3282794
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:58:05+00:00 2026-05-17T19:58:05+00:00

This question relates to this SO question and answer (rails-3-ssl-deprecation ) where its suggested

  • 0

This question relates to this SO question and answer (rails-3-ssl-deprecation
)
where its suggested to handle ssl in rails 3 using routes.rb and routes like:

resources :sessions, :constraints => { :protocol => "https" }

# Redirect /foos and anything starting with /foos/ to https.
match "foos(/*path)", :to => redirect { |_, request|  "https://" + request.host_with_port + request.fullpath }

My problem is that links use relative paths(i think thats the correct term) and once I’m on a https page all the other links to other pages on the site then use https.

1) Whats the best way to get back to http for pages where https isn’t required? Do I have to setup redirects for all them(I hope note) or is there a better way. Would the redirects be like this:

match "foos(/*path)", :to => redirect { |_, request|  "http://" + request.host_with_port + request.fullpath }

2) If redirects back to http are required, how do I handle a case where I want all methods to be http except one? ie foos(/*path) would be for all foos methods. But say I wanted foos/upload_foos to use ssl. I know how to require it

scope :constraints => { :protocol => "https" } do
  match 'upload_foos' => 'foos#upload_foos', :via => :post, :as => :upload_foos 
end

but if I put in the http redirect to the foos path what happens to https upload_foos?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:58:05+00:00Added an answer on May 17, 2026 at 7:58 pm

    If you want all your links to be able to switch between http and https, you have to stop using the _path helper and switch to _url helpers.

    After that, using a scope with the protocol parameter forced and protocol constraint makes the urls automatically switch.

    routes.rb

    scope :protocol => 'https://', :constraints => { :protocol => 'https://' } do
      resources :sessions
    end
    
    resources :gizmos
    

    And now in your views:

    <%= sessions_url # => https://..../sessions %>
    <%= gizmos_url   # => http://..../gizmos %>
    

    Edit

    This doesn’t fix urls that go back to http when you are in https. To fix that you need to override url_for.

    In any helper

    module ApplicationHelper
      def url_for(options = nil)
        if Hash === options
          options[:protocol] ||= 'http'
        end
        super(options)
      end
    end
    

    This will set the protocol to ‘http’ unless it was explicitly set (in routes or when calling the helper).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question relates to this question which I asked earlier this week. The answer
This question relates to this question . I have a EF model like this
This question relates to Francois Deschenes's answer to one of my previous questions. I
This is related to the this question and the answer maybe the same but
This question relates to an ASP.NET website, originally developed in VS 2005 and now
Background: This question relates to versions of Delphi below 2009 (ie without Unicode support
I know this is not a real programming question. But, it relates to programming
I'm pretty new to rails, so I apologize if this question has an obvious
This question relates to those parts of the KenKen Latin Square puzzles which ask
This question and my answer below are mainly in response to an area of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.