Preserve query parameters on redirect

Hi everyone, I’ve implemented the following in our netlify.toml file:

[[redirects]]
  from = "/"
  to = "/fr?utm_source=:source&utm_medium=:medium&utm_campaign=:campaign"
  force = true
  query = { utm_source = "source", utm_medium = "medium", utm_campaign = "campaign" }

From my tests, any combination of these 3 query parameters (including 2, 1 and no query parameters) in the URL lead to a correct URL. Am I missing something, or is this indeed enough to redirect for all these 3 parameters?

Hey @Floriferous, can you elaborate on what a ‘correct URL’ is? What is the true intended URL?

There’s a sample file here and this discussion will be useful for you, too!

Correct means:

  • /?utm_source=A/fr?utm_source=A
  • /?utm_medium=B&utm_source=A/fr?utm_medium=B&utm_source=A
  • Etc. no matter the order and amount of the 3 query strings I pass.

Gotcha. Unfortunately, you’re going to need a redirect rule for each of the possibilities.

If your rule specifies three parameters, our engine will expect to see all three parameters but it doesn’t matter what order they’re in. For example, this rule:

[[redirects]]
  from = "/origin"
  to = "/new/origin"
  status = 301
  query = {one = ":one", two = ":two", three = ":three"}

Will successfully redirect the following:

  • /origin?one=yes&three=yes&two=yes
  • /origin?one=yes&two=yes&three=yes
  • /origin?one=yes&two=&three=
  • /origin?three=yes&two=&one=

It will not redirect /origin?one=yes.

Repro: https://redirect-multiple-query-strings.netlify.rodeo

I tried your reproduction, and it doesn’t seem to work for /origin → /new/origin

From what I can tell, it works on our production website without specifying all other possibilities?

I would expect that you need a rule without the query string parameters, to redirect /origin to /new/origin.

If you’re not seeing this and this is still an issue, do you mind sharing your site’s app ID and/or applicable deploy ID so I can see what rules you have and check what’s actually happening?

1 Like

Sure, it’s www.e-potek.ch, and the redirect is from / to /fr.