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?
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"}
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?
I see what’s happening – it’s because we automatically pass through query string parameters now! The query strings would always be passed through, it’s just what we do.
So, you won’t actually need the second-to-last rule with the query string rules, if you want to pass these parameters through.
If you don’t want to pass them through, you’ll want to instate something like this (see section Query String Parameters).
It depends what you’re trying to do and I’m struggling to understand what you want.
If you want any sort of query string to be included in the redirect, you don’t need to specify it in a redirect rule. If you want all query strings to be passed through, remove the redirect rule containing query = { } (this was the second-to-last rule I was referring to)
If you want only specific query string parameters to be included in the redirect, you’ll want to follow the advice from before and observe the reproduction I created.