Search code examples
ruby-on-railsroutesrails-routing

How can I use Rails routes to redirect from one domain to another?


My app used to run on foo.tld but now it runs on bar.tld. Requests will still come in for foo.tld, I want to redirect them to bar.tld.

How can I do this in rails routes?


Solution

  • Bit more modern approach:

    constraints(host: 'www.mydomain.com') do
      get '/:param' => redirect('https://www.mynewurl.com/:param')
    end