Welcome! Log In Create A New Profile

Advanced

Re: Remove query parameter

Ole Laursen
June 17, 2010 11:06AM
Barry Abrahamson <barry@...> writes:

> On Jun 16, 2010, at 11:28 PM, Igor Sysoev wrote:
>
> > There is no way to remove a parameter, however, you can to define
> > cache key without a query string at all or with predefined parameters only:
> >
> > proxy_cache_key $proxy_host$uri;
> > or
> > proxy_cache_key $proxy_host$uri?$arg_one&$arg_two;
>
> The ability to blacklist specific args from the cache key would be a nice
feature :)

Indeed. Thanks for the answers!

I've figured out how to do remove parameters with the set $args syntax, it's not
pretty though. Would be trivial to do with a parser, but less trivial with
regexp, I basically remove each unwanted GET parameter one-by-one and then fixup
any stray & afterwards:

# remove GET parameters
if ($args ~ (.*)utm_source=[^&]*(.*)) {
set $args $1$2;
}
if ($args ~ (.*)utm_medium=[^&]*(.*)) {
set $args $1$2;
}
if ($args ~ (.*)utm_campaign=[^&]*(.*)) {
set $args $1$2;
}
if ($args ~ (.*)gclid=[^&]*(.*)) {
set $args $1$2;
}
# cleanup any repeated & introduced
if ($args ~ (.*)&&+(.*)) {
set $args $1&$2;
}
# cleanup leading &
if ($args ~ ^&(.*)) {
set $args $1;
}
# cleanup ending &
if ($args ~ (.*)&$) {
set $args $1;
}

Then proxy_pass and proxy_cache_key must reference $args, thankfully $is_args
appears to work even when changing $args above :)

location / {
proxy_pass http://127.0.0.1:1234$uri$is_args$args;
proxy_cache_key "$scheme$host$uri$is_args$args";
...
}


Ole


_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Remove query parameter

Ole Laursen June 16, 2010 03:46PM

Re: Remove query parameter

Igor Sysoev June 17, 2010 12:32AM

Re: Remove query parameter

Barry Abrahamson June 17, 2010 01:14AM

Re: Remove query parameter

Ole Laursen June 17, 2010 11:06AM

Re: Remove query parameter

xgdlm June 17, 2010 02:00AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 157
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready