How to drop the get arguments after redirects

Hello,

On my website (with configs described there: Website broken after upgrading to latest · Issue #1490 · netlify/next-runtime · GitHub ) I would like to have a page redirecting without keeping the GET parameters:

/blog/:id should not changed
/blog?a=:id should redirect to /blog/:id
/blog/:id?a=:a should redirect to /blog/:id
/blog should redirect to /publicPresence

as explained here (Website broken after upgrading to latest · Issue #1490 · netlify/next-runtime · GitHub) it works locally with my settings but not once deployed.

Thank you for your help !

Hey @leob_123,

I believe you should be able to get it working like:

[[redirects]]
  force = true
  from = "/blog"
  status = 301
  to = "/publicPresence"
[[redirects]]
  force = true
  from = "/blog/*"
  status = 301
  to = "/.netlify/functions/redirect/"
  [redirects.query]
    a = ":a"

Inside the redirect function:

export async function handler(event) {
  return {
    headers: {
      location: `/blog/${event.queryStringParameters.a}/?param=true`
    },
    statusCode: 301
  }
}

Note that, I’ve directly typed this without testing, so if something doesn’t work, feel free to revert.

As I’ve mentioned on the issue, I’d recommend using Edge Functions for a task like this due to its speed considerations, but you’re free to use Functions.

that is not working for me :confused: