gpt4 book ai didi

ruby-on-rails - 从旧域重定向到新域(SEO 友好)

转载 作者:行者123 更新时间:2023-12-03 21:10:46 28 4
gpt4 key购买 nike

我将 Heroku 应用程序上的自定义域更改为新域。现在我将创建一个新的 Heroku 应用程序,它的唯一目的是重定向到第一个应用程序。

我在 Google Webmasters 中读到我应该像这样进行 301 重定向:

http://old.com/anypath/123

to

http://new.com/anypath/123

我如何在 Rails 中做到这一点?

最佳答案

把它放在 ApplicationController 的前置过滤器中:

class ApplicationController
before_action :redirect_if_old

protected

def redirect_if_old
if request.host == 'old.com'
redirect_to "#{request.protocol}new.com#{request.fullpath}", :status => :moved_permanently
end
end
end

关于ruby-on-rails - 从旧域重定向到新域(SEO 友好),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7578853/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com