Redirect from old domain to new one (SEO friendly)

前端 未结 3 1812
没有蜡笔的小新
没有蜡笔的小新 2021-02-07 14:48

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.

I read in Google

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-07 15:24

    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
    

提交回复
热议问题