我正在修改一个现有的项目,我希望我的应用程序只有状态: 301重定向,而不是Rails默认302。由于应用程序中有很多使用redirect_to的地方,所以我想跳过修改它们并添加status: 301作为参数,所以如果可能的话,我希望将我的应用程序的默认rails重定向代码更改为301,或者如果不可能的话,“劫持”302重定向并将其更改为301。
提前感谢
发布于 2014-08-06 10:36:38
您可以对redirect_to方法进行类库设置:
class ApplicationController < ActionController::Base
def redirect_to_with_permanence(options = {}, response_status = {})
response_status.reverse_merge! status: :moved_permanently
redirect_to_without_permanence options, response_status
end
alias_method_chain :redirect_to, :permanence
endhttps://stackoverflow.com/questions/25157261
复制相似问题