在Rails 4路由中重定向 [英] Redirection in Rails 4 routes

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

问题描述

我的网站以前在这里拥有移动视图:

My site used to have a mobile view here:

https://www.example.com/m/home

我们已经弃用了移动视图,现在我需要一种简单的方法来修剪/ m / URL,以便请求进入正确的页面。

We have deprecated the mobile views and now I need a simple way to trim the /m/ off the URL so that the request proceeds to the correct page.

示例:

https://www.example.com/m/about => https://www.example.com/about
https://www.example.com/m/user/:id => https://www.example.com/user/:id

我希望解决这个问题在Rails路由中无需引入新的控制器动作或与Nginx混在一起。我有100多条路线。提前致谢。

I'm hoping to solve this in the Rails routing without having to introduce a new controller action or meddle with nginx. I have 100+ routes. Thanks in advance.

Rails版本:4.2

Rails version: 4.2

推荐答案

有一个重定向模块(也记录在指南)。

类似的东西:

get '/m/about', to: redirect('/about')
get '/m/user/:id', to: redirect('/user/%{id}')

可以与路由通配:通用解决方案:

Which you can combine with route globbing for a generic solution :

get '/m/*path', to: redirect('/%{path}')

这篇关于在Rails 4路由中重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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