Redirect to a different page number

Hi,

I have an old site with a different domain, for which I placed a full domain redirect that in some cases carries a page url + query string, the new website on Netlify has similar structure, but the page numbers are different, because Eleventy pagination starts from 1 on the second page, not from 2, since the first page doesn’t have number.

Is there a way to capture the number and subtract one for the redirect so /blog?page=2 goes to blog/1/ , /blog?page=3/blog/2/ and so on?

I’m adding various blocks to my toml file but wondering if there’s a better way

Thanks

Hi @ramono

Sadly, there’s no way to subtract a value in netlify.toml. However, what you can do is generate a _redirects file during your build process. Depending on the templating workflow of your SSG (Eleventy), you can probably do some math in it and generate the required file. For example, JavaScript can handle it something like:

/*
  I won't add i = 1 rule in this because that would change to /blog/0/ which would be a page not found.
  You can choose to add an if statement to check if i = 1 and use a different statement for that condition,
  but since it's just one line, I'd personally just hardcode it.
*/

// considering you need redirects from page-2 to page-10
for (i = 2; i < 11; i++) {
  console.log('/blog?page=' + i + ' /blog/' + (i - 1))
}

Interesting solution, I didn’t think of this. I’ll see if it’s worth it doing later, for now might not be necessary since I don’t post that much anyway. Thank you