1

How to write a rewrite for the Nginx that will take into account only certain parameters of query:

For example, I have a query:

site.com/guru/?g=guru1&skill=basic&unwanted=garbage

I want to receive:

site.com/guru/?g=guru1&skill=basic

I think about: https://stackoverflow.com/a/35772678/1895392

if ($request_uri ~ "([^\?]*)\?(.*)unwanted=([^&]*)&?(.*)") {
    set $original_path $1;
    set $args1 $2;
    set $unwanted $3;
    set $args2 $4;
    set $args "";
    rewrite ^ "${original_path}?${args1}${args2}" permanent;
}

Thank.

Sergey Kozlov
  • 452
  • 5
  • 17
  • Hi, is the linked SO answer not working for you ? If you can be specific about your requirement I can help you. Do you need to remove a specific parameter `unwanted` that can occur anywhere in the uri ? Or is your uri structure predictable and your need to remove everything that occurs after parameter `unwanted` including the parameter ? For ex. a simple rewrite for your use case above can be achieved using `rewrite ^(site.*)(?=&unwanted) $1` – ben5556 Oct 29 '18 at 23:13
  • The address structure is predictable. An undesirable parameter is the most recent, but it may not be. We are talking about the innovation of Facebook. Now the **fbclid=123456** parameter is added to each link. This parameter I want to exclude. Thank. – Sergey Kozlov Oct 30 '18 at 04:48

0 Answers0