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 |
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can do this with .htaccess or nginx or Apache config but a special set of circumstances forced me to use a Rails app. Could possibly be a Ruby/Sinatra script too but again, special circumstances. Happy to hear improvements to the code itself.