0

There are some good responses to this question here: NGINX: Ignoring Certain URL Parameters for Cache Purposes

But I cannot seem to get it to work. I'm running a wordpress install and here is my mapping:

map $args $cachestep1 {
  default $args;
  ~^(fbclid=[^&]*&?)(.*)$             $2;
  ~^([^&]*)(&fbclid=[^&]*)(&?.*)$     $1$3;
}

And my cachekey:

fastcgi_cache_key $scheme$host$request_method$uri$cachestep1;

I still get cache MISS on the exact same urls with different fbclids.

knofun
  • 3
  • 1

1 Answers1

1

It looks like the third regex is slightly wrong - ^([^&]*)(&fbclid=[^&]*)(&?.*)$ will not match string like a=c&c=d&fbclid=trimm&xxx=yyy.

It can be replaced with ^(.*)(&fbclid=[^&]*)(&?.*)$. Try yourself on regex101.com.

Few small improvements:

  • not capturing groups (?:...)
  • .*? - not greedy version of .* (as little characters as possible)
map $args $cachestep1 {
  default $args;
  ~^(?:fbclid=[^&]*&?)(.*)$             $1;
  ~^(.*?)(?:&fbclid=[^&]*)(&?.*)$     $1$2;
}
kupson
  • 3,578
  • 20
  • 19