Force Rails Heroku App from subdomain.herokuapp.com to apex domain?

前端 未结 3 1508
迷失自我
迷失自我 2020-12-30 15:54

What is the proper way to send a subdomain.herokuapp.com to the apex domain of the application? This is to avoid multiple domain names with the same content.

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-30 16:05

    Quoting from https://devcenter.heroku.com/articles/custom-domains

    The domain myapp.herokuapp.com will always remain active, even if you’ve set up a custom domain. If you want users to use the custom domain exclusively, you should send HTTP status 301 Moved Permanently to tell web browsers to use the custom domain. The Host HTTP request header field will show which domain the user is trying to access; send a redirect if that field is myapp.herokuapp.com.

    You can redirect requests to the "subdomain.herokuapp.com" using a before filter in ApplicationController or using a constraint in rails routing.

提交回复
热议问题