Reputation: 86
Background: We need the Wordpress plugin WP Super Cache to ignore certain query strings only ment for client side google analytics, these are the utm_ tags and gclid.
We want to try WP Super Cache because it supports different cache for mobile and non-mobile. W3 Total cache does not.
The result is that no matter whether these query string exist in the url or not, no matter what their values are, the same cached page are shown (and if the cache does not exist, it creates a new cache for the url (these query string parameters omitted)
The Wordpress plugin W3 Total Cache allows you to add such query string to ignore, it then adds them to .htaccess, like below, (including other relevant rewrite rules. We copied exactly this from W3 Total Cache .htaccess to a WP Super Cachee .htaccess
RewriteRule ^ - [E=W3TC_QUERY_STRING:%{QUERY_STRING}]
RewriteCond %{ENV:W3TC_QUERY_STRING} ^(.*?&|)utm_campaign=.*?(&.*|)$ [NC]
RewriteRule ^ - [E=W3TC_QUERY_STRING:%1%2]
RewriteCond %{ENV:W3TC_QUERY_STRING} ^(.*?&|)utm_source=.*?(&.*|)$ [NC]
RewriteRule ^ - [E=W3TC_QUERY_STRING:%1%2]
RewriteCond %{ENV:W3TC_QUERY_STRING} ^(.*?&|)utm_medium=.*?(&.*|)$ [NC]
RewriteRule ^ - [E=W3TC_QUERY_STRING:%1%2]
RewriteCond %{ENV:W3TC_QUERY_STRING} ^(.*?&|)utm_term=.*?(&.*|)$ [NC]
RewriteRule ^ - [E=W3TC_QUERY_STRING:%1%2]
RewriteCond %{ENV:W3TC_QUERY_STRING} ^(.*?&|)utm_content=.*?(&.*|)$ [NC]
RewriteRule ^ - [E=W3TC_QUERY_STRING:%1%2]
RewriteCond %{ENV:W3TC_QUERY_STRING} ^&+$
RewriteRule ^ - [E=W3TC_QUERY_STRING]
RewriteCond %{ENV:W3TC_QUERY_STRING} =""
And also added below:
RewriteCond %{REQUEST_URI} \/$ # also added from w3 super cache
Because we commented out some of WP Super Cache's lines.
# RewriteCond %{REQUEST_URI} !^.*[^/]$ # commented out from wp super cache
# RewriteCond %{REQUEST_URI} !^.*//.*$ # commented out from wp super cache
# RewriteCond %{QUERY_STRING} ^$ # commented out from wp super cache
However, it does NOT work.
And so I'm pretty sure it comes down to the last rewrite line. It was like this
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html.gz -f
RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html.gz" [L]
So I thought maybe (.*) still catches all query strings and try to pass it to the rewrite rule. So replaced it with %{REQUEST_URI} like W3 total cache does it:
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/%{REQUEST_URI}/index-https.html.gz -f
RewriteRule ^.* "/wp-content/cache/supercache/%{SERVER_NAME}/%{REQUEST_URI}/index-https.html.gz" [L]
W3 Total cache looks like:
RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html" -f
RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html" [L]
Still does NOT work. Meaning, still different caches for these query strings vs no query string. Still different caches with different values for the same query string variable.
Upvotes: 2
Views: 1048
Reputation: 431
Do you need the query string values? Are you using them to measure some kind of data or as tracking data? If not, you can remove the query string via, for example, .htaccess
. Like this:
# BEGIN Remove Google Adwords query string
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} "gclid=" [NC]
RewriteRule (.*) /$1? [R=301,L,QSD]
<IfModule mod_rewrite.c>
# END Remove Google Adwords query string
You can read more about it here: https://guides.wp-bullet.com/remove-google-adwords-gclid-query-string-htaccess/
Like stated in that article, if you are able to access AdWords, you can disable the query strings by disabling 'auto tagging'.
Upvotes: 0