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

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

问题描述

我的应用程序以前可以在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天全站免登陆