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.

It’s a little late but I still want to add that handling a large redirect list can be a pain, especially when you’re trying to maintain SEO rankings. Have you considered using a service like XDN Console to manage your redirects? That could save you a lot of time and hassle in the long run, especially if you’re dealing with a rapidly changing product base.
Also, have you ever tried to Get your FREE Competitor Analysis for your website or project? It’s a great way to see what your competition is up to and get some ideas for improving your own SEO. You can check out Crowdo’s website for some helpful insights and tips.