Large redirect list to maintain SEO (backlinks)

An SEO manager for our project has requested a large list of redirects for an upcoming Commerce release on XDN. There are limits to what we want to house in the routing (our architect is recommending 500 max) but after programmatic redirects have been put in place there are still 700+ that they’d like to include to help maintain SEO ranking.

What is the best way to handle this? Is there a possibility of increasing and improving the handling of a large redirect list?

Also, as a thought, is there a way this could be managed within the XDN Console, rather than having to deploy an updated route.js file with each new change? Would be a great feature to provide business teams managing a rapidly changing product base for campaigns.

Thanks in advance for any advice.

1 Like

The most scalable way to do it would be to have a list of paths in an environment variable and check those within a fallback, something like:

const redirects = JSON.parse(process.env.REDIRECTS) // configure this in your environment via XDN console
const FAR_FUTURE_TTL = 60 * 60 * 24 * 365 * 10 // 10 years

router.fallback(({ cache, compute, redirect, serveStatic }) => {
  compute(req => {
    // look up the redirect path from the REDIRECTS environment variable configured in XDN console.
    const destination = redirects[req.path]

    if (destination) {
      // cache the response to keep compute costs down
      cache({ edge: { maxAgeSeconds: FAR_FUTURE_TTL } })
      redirect(destination)
    } else {
      // Serve a 404 page or an app shell here, or maybe just redirect to "/". Your choice.
      res.statusCode = 404
      serveStatic('public/404.html')
    }
  })
}

This can scale to a very large number of redirects, but has a trade off being billed for compute time on all requests that don’t match a route.