Rails路由子域重定向 [英] Rails routes redirection for subdomains

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

问题描述

我们无法更改服务器配置文件,因此我们需要在rails级别进行重定向。

We can't change the server configuration files, so we need to do our redirections at the rails level.

我对外部站点的路径重定向没有问题,例如:

I have no problem with path redirections to external sites, like:

match / meow => redirect( http://meow.com/)

问题出在子域上。例如,我需要重定向:

The issue is with the subdomains. I need to redirect for example:

http://my.example .com => http://example.com

如何使用routes.rb完成此操作?

How can this be done using routes.rb?

推荐答案

根据@cfernandezlinux的惊人的答案,在 Rails 4 / Ruby 2 语法中是相同的:

According to @cfernandezlinux's amazing answer, here's the same in Rails 4/Ruby 2 syntax:

constraints subdomain: "meow" do   
  get "/" => redirect { |params| "http://www.externalurl.com" }
end




    在rails.rb中,
  • match 不再适用于Rails 4.0。您必须明确使用 get 帖子等。

  • hashrocket语法(=>)适用于旧Ruby,现在在Ruby 2.0中我们使用param:'value'语法

    • match in routes.rb is not allowed in Rails 4.0 anymore. You have to use explicitly get, post, etc.
    • hashrocket syntax (=>) is for old Ruby, now in Ruby 2.0 we use param: 'value' syntax
    • 这篇关于Rails路由子域重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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