Caching WordPress URLs with pretty permalinks and Google Analytics tags

I have run into a problem with caching on WordPress sites. Here’s what happens:

An email is sent, reaching thousands of people. Several hundred will come to the site. The problem is that the URL is constructed like so:

The utm_term tag is unique to every recipient of the email (don’t ask, Mailchimp constructs the URL like that). Nginx then ends up caching hundreds of these URLs, because $request_uri is therefore “unique” to every link and caching is set as so:

fastcgi_cache_key “$scheme$request_method$host$request_uri”;

I’ve tried replacing this line with the following as per these instructions (link):

fastcgi_cache_key “$scheme$request_method$host$uri”;

or (with accompanying setup):

fastcgi_cache_key “$scheme$request_method$host$rt_uri”;

However, this breaks the site because $uri on a WordPress install is simply /index.php , at least that is what Nginx is spitting back when I debug using headers. And I found one possible solution using Lua, but reconfiguring the server and adding Lua seems like overkill.

So, I’m still looking for a way to strip out all the Google Analytics tags and force

to show the cached version of

Hopefully my question makes sense. Any help is greatly appreciated! Thanks. :slight_smile:

Really sorry for delayed reply.

I think in your case nginx is skipping cache because mailchimp url has query string.

You config may have a line like:

        if ($query_string != "") { set $skip_cache 1; }  

Add following a line after above line:

        if ( $arg_utm_source != "" ) { set $skip_cache 0; }  

I am not able to recall much about - Cache urls which use only "javascript-related queries" but if your problem persist, just let me know.

I will try to recreate situation and try to find a “universal” workaround as this may affect many more users.