从旧域重定向到新域(SEO 友好) [英] Redirect from old domain to new one (SEO friendly)

查看:42
本文介绍了从旧域重定向到新域(SEO 友好)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I changed the custom domain on my Heroku app to a new one. Now I will create a new Heroku app which only purpose will be to redirect to the first app.

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

I read in Google Webmasters that I should do a 301 redirect like this:

http://old.com/anypath/123

to

http://new.com/anypath/123

如何在 Rails 中实现?

How do I do it in Rails?

推荐答案

把它放在 ApplicationController 的一个 before 过滤器中:

Put this in a before filter in the ApplicationControlller:

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

这篇关于从旧域重定向到新域(SEO 友好)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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