Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
Created June 26, 2015 16:46
Show Gist options
  • Save ChrisLTD/c59775288e321de76028 to your computer and use it in GitHub Desktop.
Save ChrisLTD/c59775288e321de76028 to your computer and use it in GitHub Desktop.
Apex domain redirect in Rails 4
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :check_domain_and_ssl
def check_domain_and_ssl
if Rails.env.production? and (request.protocol.downcase + request.host.downcase) != 'https://www.mywebsite.com'
redirect_to 'https://www.mywebsite.com' + request.fullpath
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment