Last active
October 26, 2018 14:15
-
-
Save paulmwatson/c5c669f5478244ebadea12d3b0087103 to your computer and use it in GitHub Desktop.
A Rails route.rb rule that will redirect any GET to another domain and maintain the path, query, and hash/fragment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
get '(*path)', to: redirect{|params, request| "#{ENV['DOMAIN_TO_REDIRECT_TO']}#{request.url.gsub(request.scheme, '').gsub('://', '').gsub(request.host + '/', '')}"} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A nice improvement would be maintaining the original sub-domain but that means you also need a wild-card SSL certificate. Heroku, which this route.rb is hosted on for my purposes, doesn't allow wild-card custom domains over SSL.