skip to Main Content

To improve the SEO on my site I’d like the different variations of my domain to link to one main site.

For example right now https://example.com and https://www.example.com both access the same domain and are viewed as different websites by Google.

I’m hosting my Rails app on Heroku and then connecting to the domain I purchased through DNSimple. Does anyone know how to get all of these websites to redirect to https://www.example.com?

I’ve followed different tutorials on Heroku (adding domains) and DNSimple (adding an ALIAS), but nothing has worked.

2

Answers


  1. Keeping your site hosted on two different domain does not mean improved SEO, in facts it duplicate content for Google and is not appreciated.

    To improve your SEO you should be doing a 301 redirect to the domain which you want to be shared as primary domain.

    About setting your preferred domain (www or non-www).

    On setting up redirect – Heroku how to redirect http:// to http://www

    Login or Signup to reply.
  2. There are a few complications here.

    The first complication is that you want to redirect an hostname which is using HTTPs. In fact, normally you could use the DNSimple URL record, but it doesn’t work with https as you would need to install the SSL certificate on DNSimple servers (HTTP redirect header is sent after the HTTPS negotiation).

    One option would be to redirect at server level, but since your app is hosted on Heroku you have no control over the server configuration.

    Therefore, in your case the only option is to point the various domains to the same Heroku application, add the domains as custom domains to your Heroku app and handle the redirect internally. That means your app should check whether a request comes from one of the alternate domain and if that’s the case it redirects to the canonical domain.

    There are several ways to check it in a Rails app. The most effective is probably using a custom middleware or the Rails router file, so that the request is handled as soon as possible and it doesn’t build an entire request stack in the app, as it would happen for instance with a before_action.

    On the DNSimple side, you will just have to create an ALIAS record (if the hostname you want to resolve is an apex domain) or a CNAME record (if the hostname is a subdomain) that points to the same Heroku SSL endpoint of your application.

    However, the last complication is that Heroku doesn’t allow multiple certificates for the same app. If the domains you want to redirect to the canonical one belongs to the same name (e.g. are subdomains) you can just purchase a wildcard certificate. Otherwise, if you want to cover multiple different domains in the redirect, you will need a multi-domain SSL certificate.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search