Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
litespeed_wiki:cache:drop_query_string [2017/12/01 22:03]
Eric Leu [More information]
litespeed_wiki:cache:drop_query_string [2021/11/11 20:54] (current)
Lisa Clarke Fixed redirect link
Line 1: Line 1:
-====== Drop certain query string parameters based on rules to make request more efficient ====== +~~REDIRECT>​https://​docs.litespeedtech.com/​lscache/start/#dropping-query-strings~~
-This function is suit for users who's site bring junk query string, e.g. UTM code, and get too many different URLs which should store and serve with same cache but not. \\ +
-Let's introduce a little about what is a UTM code? +
-A UTM code is a simple code that you can attach to a custom URL in order to track a source, medium, and campaign name. This enables Google Analytics to tell you where searchers came from as well as what campaign directed them to you.  +
- +
-Starting with version 5.2.3, LSWS has a built-in Drop certain query string parameters based on rules system. +
- +
-===== How to Enable LSWS WordPressProtect Feature on cPanel ===== +
- +
-As long as LSWS version is 5.2.3 or above, the LSWS Drop certain query string feature is enabled by default and does not need any extra configuration in the LSWS WebAdmin GUI or in Apache configurations.  +
- +
-You may wish to override the default settings at the server level, virtual-host level or even the ''​.htaccess''​ level. Before making any changes. +
- +
-The upper level configuration is inherit by lower level. if lower level add more configuration,​ it is in addition to the upper level.(the addition feature may not be fully implemented yet, will be fully implemented). If want to get rid of upper level config, need to do "​clear",​ then add new config. +
- +
-Let's look at some examples for a WHM/cpanel EA4 environment:​ +
- +
-After you run the following, the WordPressProtect feature will be automatically enabled globally: +
-  /​usr/​local/​lsws/​admin/​misc/​lsup.sh -f -v 5.2.3 (or above version) +
- +
-You may wish to set a rule. You will need to set it at the server level of the Apache configuration file: +
- +
-  vi /​etc/​apache2/​conf.d/​includes/​pre_main_global.conf +
-   +
-and add: +
-  <​IfModule Litespeed> +
-  CacheKeyModify -qs:utm* +
-  </​IfModule>​ +
- +
-This will drop all query strings that the name part starts with "​utm" ​ for all virtual hosts. +
- +
-You can also drop query string with name exact matches "​utm":​ +
-  <​IfModule Litespeed>​ +
-  CacheKeyModify -qs:utm +
-  </​IfModule>​ +
- +
-No matter how the server level is set, the end user has the ability to clear it through ''​.htaccess''​ by adding the following:​ +
- +
-  <​IfModule Litespeed>​ +
-  CacheKeyModify clear +
-  </​IfModule>​ +
- +
-To verify the server and virtual host level settings, you may run the following command: +
- +
-  cd /​etc/​apache2/​ +
-  grep -i -r CacheKeyModify +
- +
-The design logic looks like the following:  +
-We use ''​A'',''​B'',''​C''​ instead of rules. +
-^ Server Level ^ VHost Level^ .htaccess ^ Result ^ +
-|A|not set|not set|A| +
-|A|not set|C|A+C| +
-|A|B|not set|A+B| +
-|A|B|C|A+B+C| +
- +
-  * The addition feature may not be fully implemented yet on v 5.2.3, but will be fully implemented on next release. +
- +
-===== How to check===== +
-==== Prepare URL with junk query string==== +
-Assume we have a public WordPress site with domain ''​testquerystring.com''​ and LSCache enabled. And use Campaign URL Builder, e.g.[[https://ga-dev-tools.appspot.com/​campaign-url-builder/​ | Campaign URL Builder]] or other UTM plugin to generate URL, which will looks like this: {{:​litespeed_wiki:​cache:​utm.png?​700|}} \\ +
-Now, I can access my site with both of URLs: +
-  * <​nowiki>​https://​testquerystring.com </​nowiki>​ +
-  * <​nowiki>​https://​testquerystring.com/?​utm_source=google&​utm_medium=email&​utm_campaign=promo%20code</​nowiki>​ +
- +
-==== Setup rules to drop query string==== +
-For testing purpose, we can simply add the following to .htaccess file +
-<​code>​ CacheKeyModify -qs:​utm_medium </​code>​ +
-==== Verify from dev tool==== +
-  * Before setup rules: +
-    * All king of query strings with same domain will store with different cache key. Above URLs will store 2 cache files +
-  * After setup rules: +
-    * All king of query strings with same domain will store with same cache key. Above URLs will store only one cache files +
-    * I can access these urls and [[ https://www.litespeedtech.com/​support/wiki/doku.php/​litespeed_wiki:​cache:​lscwp:​troubleshooting:​general?​s[]=hit#testing | check cache]] are hit at first time visit. +
-      ​<​nowiki>​https://​testquerystring.com/?​utm_source=google&​utm_medium=email1&​utm_campaign=promo%20code</​nowiki>​ +
-      ​<​nowiki>​https://​testquerystring.com/?​utm_source=google&​utm_medium=email12&​utm_campaign=promo%20code </​nowiki>​ +
-      - <​nowiki>​https://​testquerystring.com/?​utm_source=google&​utm_medium=email123&​utm_campaign=promo%20code </​nowiki>​ +
-      - <​nowiki>​https://​testquerystring.com/?​utm_source=google&​utm_medium=email1234&​utm_campaign=promo%20code</​nowiki>​ +
- +
-==== Verify from debug log==== +
-We can only check keywords ''​QS''​ & ''​KEY''​ with ''​CACHE''​ tag from debug log: +
-  tail -f /​etc/​apache2/​logs/​* | grep '​CACHE'​ | grep '​QS\|KEY'​ +
- +
-Verify ''​utm_medium''​ has been removed from CacheKey data -> QS +
-<​code>​ +
-[CACHE] Remove exact matched QS key [utm_medium],​ +
-[CACHE] modified QS in cache key is [], +
-[CACHE] CacheKey data: URI [/​testquerystring.com/?​],​ QS [utm_source=google&​utm_campaign=promo%20code],​ Vary Cookie [_lscache_vary=xxxxx],​ Private Cookie [wp_woocommerce_session_xxxxx],​ IP [x.x.x.x] +
-</​code>​ +
- +
-====More Flexibility==== +
-It also can be set via rewrite rule and it support multiple env combined.  +
-<​code>​ +
-Rewritecond %{QUERY_STRING} '​utm_source=google&​utm_medium=email1&​utm_campaign=promo%20code'​ +
-RewriteRule ​ .* - [E=cache-key-mod:​-qs:​utm_source,​ E=cache-key-mod:​-qs:​utm_medium*] +
-</​code>​ +
-Logs +
-<​code>​ +
-Remove exact matched QS key [utm_source],​ +
-Remove prefix matched QS key [utm_medium],​ +
-CacheKey data: URI [/​wordpress/?​],​ QS [utm_campaign=promo%20code],​ +
-</​code>​ +
- +
- +
-====More information==== +
-If you change rule from ''​utm_medium''​ to ''​utm_medium*'',​ log will shows: +
-  Remove prefix matched QS key [utm_medium] +
- +
- +
- +
-=====Refer===== +
-[[https://​www.launchdigitalmarketing.com/​what-are-utm-codes/​ | UTM Codes article]]+
  • Admin
  • Last modified: 2017/12/01 22:03
  • by Eric Leu