Welcome! Log In Create A New Profile

Advanced

Preserve only specific query string params

Posted by pmisinsky 
Preserve only specific query string params
October 26, 2021 05:36AM
Dear nginx support,

I am struggling how to setup nginx in order to preserve some specific group of query string params and at the same time to remove all the other present query params in origin url.
In specific I would like to only keep following query params in Url:

utm_source
utm_medium
utm_campaign
___store
dclid

All the other params should be stripped off.

Let's say I have Url https://www.example.com/de/aktionen/?id=8&&utm_source=newsletter&utm_medium=email&utm_campaign=aktionennewsletter_fr

This Url should be changed to https://www.example.com/de/aktionen/?utm_source=newsletter&utm_medium=email&utm_campaign=aktionennewsletter_fr (i.e "id=8" would be stripped off)

Problem is that I DO NOT KNOW which specific param could be called by end-user. In above example it is "id=8" but on he other hand I see in access.log also e.g.

https://www.example.com/de/qualitaet/qualitaetsanspruch/testergebnisse/?kh=191212145210061982&l=de&o=0&a=12211026094918233309&utm_source=newsletter&utm_medium=email&utm_campaign=aktionennewsletter_de

In this case I see more unwanted query params ( "kh=191212145210061982" and "l=de" and "o=0" and "a=12211026094918233309" ) that I want to strip off to final URL https://www.example.com/de/qualitaet/qualitaetsanspruch/testergebnisse/?utm_source=newsletter&utm_medium=email&utm_campaign=aktionennewsletter_de

Basic question from my side: Is it possible to setup some general config rule that would only preserve whitelisted params - "utm_source" ,
"utm_medium" , "utm_campaign" , "___store" , "dclid" - and all the other query params would be stripped off?

Thank you for any help
Re: Preserve only specific query string params
October 26, 2021 05:51AM
Hello,

I want to add more pieces of information regarding my problem.

1. I do not know the name of unwanted query param - it could be id=8 in one url and on the other url the name of unwanted query param could be totally different - see above example

2. I do not know the position of unwanted query param that should be stripped off from original url. It could be on the first position (?id=8) as here https://www.example.com/de/aktionen/?id=8&utm_source=newsletter or on the other position of query string - e.g. second position (?utm_source=newsletter&id=8) as here https://www.example.com/de/aktionen/?utm_source=newsletter&id=8
Re: Preserve only specific query string params
October 26, 2021 05:59AM
https://stackoverflow.com/questions/65716736/how-to-get-a-part-of-url-nginx-rewrite-lua

---
nginx for Windows http://nginx-win.ecsds.eu/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 85
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready