【发布时间】:2014-02-12 03:43:13
【问题描述】:
我的应用程序旧网址是(在 php 中)
www.abc.com/athlete/?country=2
现在新的网址是(在 Rails 中):
www.asdf.com/athletes/?c=2
现在,我需要将旧网址重定向(谷歌抓取)到新网址。通过config/routes.rb
或通过控制器中的重定向,使用将一个 vertual 操作重定向到
def redirect_to_index
redirect_to :action => :index, :c => params[:country], :status => 301
end
但问题是有很多旧网址没有参数,即没有country。但在重定向时,我将始终拥有?c=。
我不想使用粗略的代码
def redirect_to_index
if params[:country]
redirect_to :action => :index, :c => params[:country], :status => 301
else
redirect_to :action => :index, :status => 301
end
end
有更好的解决方案吗?
【问题讨论】:
-
最好如果
routes.rb可以处理match "/athlete/?country=:country" => redirect("/athlete/?c=:country")这样的情况
标签: ruby-on-rails ruby redirect routes