如何使用 Rails 路由从一个域重定向到另一个域? [英] How can I use Rails routes to redirect from one domain to another?

查看:16
本文介绍了如何使用 Rails 路由从一个域重定向到另一个域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序曾经在 foo.tld 上运行,但现在它在 bar.tld 上运行.请求仍然会进入 foo.tld,我想将它们重定向到 bar.tld.

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.

我如何在 rails 路线中做到这一点?

How can I do this in rails routes?

推荐答案

这适用于 Rails 3.2.3

This works in Rails 3.2.3

constraints(:host => /foo.tld/) do
  match "/(*path)" => redirect {|params, req| "http://bar.tld/#{params[:path]}"}
end

这适用于 Rails 4.0

This works in Rails 4.0

constraints(:host => /foo.tld/) do
  match "/(*path)" => redirect {|params, req| "http://bar.tld/#{params[:path]}"},  via: [:get, :post]
end

这篇关于如何使用 Rails 路由从一个域重定向到另一个域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆