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

后端 未结 6 1015
栀梦
栀梦 2020-12-02 23:59

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 rou

6条回答
  •  情书的邮戳
    2020-12-03 00:18

    similar to other answers, this one worked for me:

    # config/routes.rb
    constraints(host: "foo.com", format: "html") do
      get ":any", to: redirect(host: "bar.com", path: "/%{any}"), any: /.*/
    end
    

提交回复
热议问题