score:0

at least when using vercel, you can archive this by repeating the parameters from the has in the destination but leaving the value empty.

e.g.:

{
   source: '/page',
   has: [
       { 
          type: 'query',
          key: 'foo'
       }
   ],
   destination: '/page/:foo?foo=',
   permanent: true
}

parameters that already exit in the destination won't be copied over and parameters with an empty value in the destination will be removed completely.

score:4

you can use middleware.

just parse the query parameter yourself and add redirection.

store a file _middleware.ts below the pages directory:

export async function middleware(req: nextrequest) {
    const { pathname } = req.nexturl;
    
    if (// your-thing ) 
        return nextresponse.redirect(//your-url);

    return nextresponse.next();
}  

maybe there is a different way, i don't know, but it doesn't matter.


Related Query

More Query from same tag