Preserve query parameters on redirect

I’m trying to preserve query parameters when redirecting internally, but haven’t found the right combination of rules in netlify.toml.

An example of what I’m trying to achieve would be having:
/author/brittany-yoon/?utm_source=facebook
retain the query parameter when redirected to /blog/?utm_source=facebook.

I’ve tried using :utm_source in the query, from and to values for a [[redirects]] rule in netlify.toml, but no luck yet.

Can someone help point me in the right direction? From the documentation I’ve read, it’s possible to redirect and convert query parameters to part of a path string but I’m trying to retain my query parameters on a new path.

Thank you!

1 Like

Hi @vanwap,

You should be able to include your query params in your redirect rule. There is an example in our netlify.toml reference doc.

Thank you @futuregerald.

The documentation seems to reference doing this for converting a query string to a path, but I did figure out how to get it working with just the query string to query string instead.

It’s just unfortunate that every single possible combination of query string parameters has to be defined.

hi vanwap, would you mind posting your working solution so others can see how you did this?

as far as different redirect behaviour goes, please outline your use case here:

thanks.

1 Like

Hi, I need to preserve some query parameters (all by default would be great). I am trying to do so through my _redirects file but I haven’t been able to do so yet. I have tried things like:

/admin/* queryParam=:qp https://outside.site/:splat?queryParam=:qp 301
/admin/* https://outside.site/:splat 301

But the query param gets ignored anyway, with or without the first rule, and writing the query param on the to url or not. I’ve also tried to force the first redirect, without change. Is there a way to do this with Netlify?

@adrm - does Gerald’s response to this question provide an answer for you at all?

@adrm @futuregerald @perry

Here is the solution I found, although we ended up giving up on preserving our query parameters all together, since using this solution would require thousands of lines of code for only ~100 redirects. The reason for this is we had 9+ possible query parameters for each redirect, meaning that each possible combination had to be accounted for.

Here is a _redirects file example.

/path1/ param1=:value1 param2=:value2 param3=:value3 /path2/?param1=:value1&param2=:value2&param3=:value3
/path1/ param1=:value1 param2=:value2 /path2/?param1=:value1&param2=:value2
/path1/ param1=:value1 param3=:value3 /path2/?param1=:value1&param3=:value3
/path1/ param2=:value2 param3=:value3 /path2/?param2=:value2&param3=:value3
/path1/ param1=:value1 /path2/?param1=:value1
/path1/ param2=:value2 /path2/?param2=:value2
/path1/ param3=:value3 /path2/?param3=:value3
/path1/ /path2/

Done from memory but should be correct. You can see why listing all the possible combinations is a bit laborious, even for a single redirect.

2 Likes

You could probably write a script to dynamically generate the _redirects file and output all possible query parameter combinations, to save doing it manually.

1 Like

This is really painful Netlify. We run a geo-localised site that always redirects users to a country specific subdirectory. So when we post content on social media or ads we use our tld/path and then use :splat to make sure customers get the country specific version.

Based on the current implementation our marketing team would have to specify every combination of utm campaign, source, medium etc.

There absolutely needs to be a solution to configure :splat to pass through url parameters.

2 Likes

Yup, that’s effectively the advice we give folks. If you have only a few possible query string args, it’s doable. When you have dozens of paths AND dozens of optional QSA’s then it becomes unwieldy though.

Yup, our Support team agrees and is fighting for the users in the prioritizing of work with our product team. As I think I mentioned to you, it’s an open feature request to which we’ve added your voice.

5 Likes

Thanks @fool,
That’s all we can ask for I guess - I appreciate the transparency. We really like the product and some of the new stuff you’re building are ace (dev, large assets, analytics etc). However, if marketing groups are a key target for you, then this is really table-stakes stuff that has to work.

+1 – please implement a “preserve all query params” option!

1 Like

Thank you for prioritizing this issue, @fool! This is a major problem for my company.

Any success getting this prioritised @fool?
Continues to be major pain for us.

thanks for continuing to ask! The more specifically you outline how this affects your business, the more useful your feedback is - are there any details you can share about how this impacts you, how many people, etc?

Sure thing.

  • Put yourself in the shoes of someone who is responsible for the marketing expenditure and demonstrating a return on investment for your spend. Let’s say you’re spending $50K a month on digital advertising and need to know which of your paid and organic channels and campaigns are performing best.
  • If you require any type of redirection, then choosing to use Netlify is a choice to compromise your ability to report on return on investment. To elaborate further:
  • UTM parameters are the bread and butter of campaign and channel tracking for most marketers. Let’s say you serve a translated or localised site based on country and language.
  • When you launch a new campaign via email, social media, mulitple paid advertising channels, you want to be able to customise the utm_source, utm_campaign and sometimes others such as utm_term.
  • Using Netlify, if you post links to those marketing channels, and you use your primary domain for the links, then when the user is redirected to their language/location subdomain, Netlify will nuke your utm parameters, eliminating the ability as marketers to measure the effectiveness of the campaign.
  • This is currently affecting our business to the tune of close to a million dollars in expenditure that we can’t track effectively and a high prospect of missed growth opportunities due to poor feedback cycles on marketing campaigns.
  • I would also argue that it is unexpected behaviour. The fact that you can put a * wildcard on your redirects and Netlify picks and chooses what included in the wildcard is a strange indeed. It has that feel about it that there is a technical concern that’s driving a poor product management position. I can’t understand otherwise why Netlify would hold a position that the current behaviour should be expected.
3 Likes

thanks @agworld - this is a very comprehensive summary. We’ll keep you all updated when there is news to share.

Not sure how to upvote or join, but this is very problematic for us as well.
We’re thinking of migrating our sites to Netlify, and we have a lot of legacy urls pointing to our site with tons of different query params.

We can’t know in advance what would be the query params that folks use, as they are chosen by marketing folks at times, by third party at other times.

Given that we’re about to sign up for the enterprise tier, I would love to understand what is the status of this feature request as it may be blocking us from continuing, or needing to go to other unsupported solutions like putting a reverse proxy in front of Netlify (Trying to set up a nginx reverse proxy fails - #5 by fool)
Which isn’t supported by you guys.

cc @fool

Thanks for that additional context @altryne ! I’ve seen some discussion of this situation recently so I’ll check in with the dev and product teams to see if I can give any status updates. Are you already working with anyone on the sales team so I can loop them in on this discussion?