Some questions to Vary Cache by Country




Wordpress LScache Plugin: Some questions to Vary Cache by Country

Last Updated on: Wed, 15 Apr 2026 00:00:02
Hi, first of all, i tested litespeed yesterday and it was awesome! Really a great tool! My site has different widgets for users of specific countrys. Yesterday i tried it with this rule: Now i have read that there is a solution with RewriteRule . ? [E= cache-vary:aff ] where aff is the cookie name of the country (so i understood, i hope i am right). I am not using woocommerce or something. Do you know any plugins or how i could set a cookie for the country? The widget plugin i am using has rules like if user is not from italy and without caching its working. Another question would be: Would it be possible that no caching for every own country is made? Sor example: One Caching for italy,germany and one caching for the rest? And last question: When there is no cookie set or country unklnown, is there a possiblity to not cache these users or show the cache of a specific country? Thanks a lot! I am hoping so much that I can use this tool And one more information: I am having geoip in php and implemented this function in wordpress function ip_info($ip = NULL, $purpose = location , $deep_detect = TRUE) $output = NULL if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) $ip = $_SERVER[ REMOTE_ADDR ] if ($deep_detect) if (filter_var(@$_SERVER[HTTP_X_FORWARDED_FOR], FILTER_VALIDATE_IP)) $ip = $_SERVER[HTTP_X_FORWARDED_FOR] if (filter_var(@$_SERVER[HTTP_CLIENT_IP], FILTER_VALIDATE_IP)) $ip = $_SERVER[HTTP_CLIENT_IP] $purpose = str_replace(array( name , , , , - , _ ), NULL, strtolower(trim($purpose))) $support = array( country , countrycode , state , region , city , location , address ) $continents = array( AF => Africa , AN => Antarctica , AS => Asia , EU => Europe , OC => Australia (Oceania) , NA => North America , SA => South America ) if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) $ipdat = @json_decode(file_get_contents( http://www.geoplugin.net/json.gp?ip=. $ip)) if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) switch ($purpose) case location : $output = array( city => @$ipdat->geoplugin_city, state => @$ipdat->geoplugin_regionName, country => @$ipdat->geoplugin_countryName, country_code => @$ipdat->geoplugin_countryCode, continent => @$continents[strtoupper($ipdat->geoplugin_continentCode)], continent_code => @$ipdat->geoplugin_continentCode ) break case address : $address = array($ipdat->geoplugin_countryName) if (@strlen($ipdat->geoplugin_regionName) >= 1) $address[] = $ipdat->geoplugin_regionName if (@strlen($ipdat->geoplugin_city) >= 1) $address[] = $ipdat->geoplugin_city $output = implode( , , array_reverse($address)) break case city : $output = @$ipdat->geoplugin_city break case state : $output = @$ipdat->geoplugin_regionName break case region : $output = @$ipdat->geoplugin_regionName break case country : $output = @$ipdat->geoplugin_countryName break case countrycode : $output = @$ipdat->geoplugin_countryCode break return $output Expand Would it be possible with this? And i think final questions: Am i right when i say Pages that have country code inside always have to be set as Private Cached URIs ? And would that be the solution maybe? RewriteRule . ? [E=Cache-Control:vary=% ENV:geoip_country_code_by_name($_SERVER[REMOTE_ADDR]) ] Tested it now for one hour with different vpn countires and it seems that my last post is the solution, but i will test further ? Now it would be only interesting how to make a cache for example italy and one for all other countrys Hi, Perhaps this topic will give you idea and useful information. you may need to have a GeoIP module on your server in order to vary it on GeoLocation Assuming you have GeoIP module on server, then use rewrite rule like this : RewriteCond % ENV:GEOIP_COUNTRY_CODE IT RewriteRule . ? [E=Cache-Control:vary=IT] RewriteCond % ENV:GEOIP_COUNTRY_CODE !IT RewriteRule . ? [E=Cache-Control:vary=not-IT] Best regards, Thank you i will test it. Just have seen that my solution was not as expected. WIll give you an update tomorrow. Is it correct that all pages depending on country code have to be set as private? Hi, No really , if incoming visitor are guest user, they can be all public as well. Best regards, Tried this but doesnt work RewriteEngine on RewriteRule . ? [E=Cache-Control:vary=other] #set default vary to other RewriteCond % ENV:GEOIP_COUNTRY_CODE_BY_NAME DE RewriteRule . ? [E=Cache-Control:vary=DE] Hi, Have you enabled Geo IP module ? create a phpinfo page, see if you can find the geo ip variable inside of it you should see something like this https://i.imgur.com/EDfo5k3.png Best regards, Thanks for your fast response. No i cant find it. I thought it would be there because when i made a php file with the code geoip_country_code_by_name it worked, but all other geo_ip-codes didnt work. So it seems i was wrong with geoip :/ Thank you anyway for your help. Its really difficult to find a solution for my problem with countrys. Have a nice day! Hi, No, the rewriterule and vary will be set before you hit PHP, and if it hits cache, PHP code wont be executed, thats the reason why this needs to use server level geoip module. If you are using LiteSpeed, it should be easy to set up in few minutes Please check this wiki Best regards, I am on a shared hosting. I have just opened a ticket there but i think they wont do it. Then didnT enable crawler too yesterday . Hi, Then only other viable way is to enable cloudflare, it sends country in header, like the case I provided in my first reply Best regards, I would like to say thank you again. It seems to work now with cloudflare as you said. Will test further, especially when i update the page and so on but at the moment everything looks fine. Thanks again for helping after so many questions of me Hi, Glad to know it works for you Best regards,



LiteCache Rush: Speed comes from using less, not from doing it faster



Reference