带有 url 重定向的 rails 句柄 404 [英] rails handle 404 with url redirect

查看:43
本文介绍了带有 url 重定向的 rails 句柄 404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用 Rails 将我确信在 Internet 上存在的链接从我的旧域重定向到新域.

I am looking to use rails to redirect links that I am sure are out there on the internet from an old domain of mine to a new one.

我想取地址example.com/about(about将不再存在)

I would like to take address example.com/about ( about will not exist anymore)

并在我的 application_controller 中获取 404,检查 url,然后重定向到

and in my application_controller to take the 404, inspect the url and then redirect to

newexample.com/about

newexample.com/about

最好的方法是什么?

推荐答案

将此添加到 Routes 文件的末尾:

Add this to the end of your Routes file:

map.connect '*path', :controller => 'some_controller', :action => 'some_action'

这将捕获任何 404.在将处理此路由的控制器和操作中,使用 params[:path] 检查 url.然后您可以根据 params[:path] 中包含的任何内容redirect_to.

This will catch any 404. Within the controller and action that will handle this route, use params[:path] to examine the url. Then you can redirect_to based on whatever is contained in params[:path].

这篇关于带有 url 重定向的 rails 句柄 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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