Redirect from old domain to new one (SEO friendly)

前端 未结 3 1813
没有蜡笔的小新
没有蜡笔的小新 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:14

    In your controller action:

    redirect_to "http://new.com#{request.request_uri}", :status => 301
    

    However, Heroku has what may be a slightly better option for you documented in their dev center:

    class ApplicationController
      before_filter :ensure_domain
    
      APP_DOMAIN = 'myapp.mydomain.com'
    
      def ensure_domain
        if request.env['HTTP_HOST'] != APP_DOMAIN
          # HTTP 301 is a "permanent" redirect
          redirect_to "http://#{APP_DOMAIN}#{request.request_uri}", :status => 301
        end
      end
    end
    

提交回复
热议问题