Answered

How do you handle redirects in Gatsby/JAMstack?

This is posted on behalf of a user.

A few of our clients are "redirect happy" and have quite a bit of them in the URL Redirections section for instances set up to use the ASP.NET sync model. Now that the server is out of the picture on dealing with requests, what's the approach with JAMStack and redirects?

I've found a few options:

  • Cloudflare with Workers that handle the redirect on requests.
  • Netlify has a _redirects file. That file could be generated by Gatsby based on redirects set in Agility.
  • Azure CDN. The redirects would have to be defined in Azure, instead of Agility, which makes it a no for me.
  • WebApp/VM hosting: Not really JAMStack to host the site on a server!

Depending on what a client is ok with paying for; I lean towards the Cloudflare or Netlify options. Is there another and/or suggested an option that your team has discovered?

1

Comments

1 comment
  • Official comment

    In our Agility Content Fetch JS SDK we have the ability to query Url Redirections. This means you can retrieve the list in JavaScript using any JAMstack framework - including Gatsby. While the Agility CMS Gatsby Source Plugin won't yet automatically create redirects for you (it will in an upcoming version), you can write your own code to fetch the list and create redirects in your gatsby-node.js. The same thing can be done in other frameworks such as NextJS.

    Now, by default these all get created as client-side redirects, not ideal. To handle them server-side, this requires integration with your hosting provider. 

    If you are using Netlify:

    If you are using other hosting providers, then you can also in theory use APIs in your build process to create/update/manage the redirects in your static hosting platform.

    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post