Conditional redirect when there is a certain query parameter

We’re trying to make the app redirect to 404 when anyone is trying to reach a URL with ?page=x in it but only if not a shop page which is meant to be paginated. So there is a rule in our netlify.toml:

  from = "/*"
  to = "/404"
  status = 404
  force = false
  conditions = {Query = ["page"]}
  except = ["/shop/*"]

But it doesn’t seem to do anuthing as, say, /about?page=3 still opens. Did we set the rule wrong? Is it achievable in the first place?

If that’s related, we’re using Next.js. The site name is withflitch.

The redirect should be:

  force = true
  from = "/*"
  to = "/404"
    page = ":page"

You can’t exclude shop though - not sure where you got that piece of config from. You can look into Edge Functions which can give you complete control over redirects.

1 Like