skip to Main Content

I just finished working on an app using GatsbyJS. I’m hosting my web application on heroku. I have a custom domain reversed through heroku with SSL support. Now I’m able to visit the following domains:

http://myapp.com
https://myapp.com
http://www.myapp.com
https://www.myapp.com

Normally you want to have 301 redirects from www to non-www and from http:// to https://. Since the heroku router does not have the ability to force SSL, they want you to handle the redirects on the application level.

I did not found any solutions for SEO optimized 301 redirects within GatsbyJS.

Any help appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    I just figured out how to get it to run on heroku. Since I did not find any solutions from gatsby itself, I adjusted my deployment to match the gatsby docs. I now use heroku buildpacks to build my project. While doing so, you can define a file called static.json.

    This file has options like "https_only": true, "canonical_host": "yoursite.com"

    With these options, heroku prepares the app to have a redirect from www to non-www and http to https. More information here: https://www.gatsbyjs.org/docs/deploying-to-heroku/


  2. Not familiar with Heroku but if 301 redirect is not possible just ensure your pages have <link rel="canonical" href="" /> tags. That is a way to hint the search engines the URL you want to be indexed. Additionally you may redirect to https:// on the client using the onClientEntry API.

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