Cache based on Location




Wordpress LScache Plugin: Cache based on Location

Last Updated on: Wed, 15 Apr 2026 00:00:02
Hi Team, I have already Enabled GeoLocation Support on the Litespeed server and its working as expected, also I have added RewriteRule . ? [E=Cache-Control:vary=% ENV:GEOIP_COUNTRY_CODE ] to enable cache vary and it is also working, but I am looking for a bit custom solution. I want the cache for India and rest of the world (only two cache copies). Not different for each country. Also How can I implement Mobile cache vary along with GeoLocation cache Vary. Hi, you just need play around a bit with rewrite rules e.g. RewriteCond % ENV:GEOIP_COUNTRY_CODE IN [NC] RewriteRule . - E=Cache-Control:vary=is_india] make sure the env given is GEOIP_COUNTRY_CODE , you can verify it by phpinfo page for mobile cache vary just enable it in setting , it will be total 4 varies 1. india + desktop 2. india + mobile 3. no-india + desktop 4. no-india + mobile Best regards, Hi, I was Going through your plugin documentation and I am Quoting here. Unlike vary cookies, a vary value is not made up of a key/value pair. It is simply an environment value, and it may only be used once. If multiple vary values are set, only the last one is used https://docs.litespeedtech.com/lscache/devguide/advanced/ Which means, Both Geo Detectiona and mobile detection cant be used at the same time, do you how can I make that work? Hi, oh yes , my bad you can use % ENV:LSCACHE_VARY_VALUE within rewrite rule to pass it onto next vary rule e.g. RewriteCond % ENV:GEOIP_COUNTRY_CODE IN [NC] RewriteRule . - E=Cache-Control:vary=% ENV:LSCACHE_VARY_VALUE +is_india] Best regards, Hi Sorry to bother you again but I have Two questions. 1. Do I need to enable Mobile caching from Plugin settings first, To make these Two-line work, which you have provided above? 2. The Code is ready to use or was it just an example to showcase How it can be achieved. if it was just an example, could be please provide the exact code which I can use, I am not very good with this .htacess rewrites. I am using the GEOIP_COUNTRY_CODE Environment variable to detect Location. Hi, yes you still need to enable mobile cache make sure this rule is added AFTER LSCWP block and before WP rewrite rule yes , its ready to use for India vary Best regards, Nothing is working now, All I am getting is 404 from Litespeed Server. And Yes I followed your Instruction, and I exactly pasted before WP rewrite rule Could you please check your code again? BTW How did you reach to conclusion using is_India in E=Cache-Control:vary=% ENV:LSCACHE_VARY_VALUE +is_india]? when you have 404 , try access any static files , if static file gives 200 , that means something wrong with your .htaccess rules and if you comment out these 2 lines, does it back to normal ? is_india is just the vary name you want to create, you can call it whatever you want , like yes , or test or something RewriteCond % ENV:GEOIP_COUNTRY_CODE IN [NC] RewriteRule . - [E=Cache-Control:vary=% ENV:LSCACHE_VARY_VALUE +is_india] in human word , these 2 lines : 1. check if geo code is IN , which refer to India in CC code 2. if true , then add is_india to current vary value 3. if false, pass it like nothing happens. sorry , had a typo , missed [ in rule , try copy the rule from my last reply , it should work e.g Yes, Code is correct IN for india, also I tried US for USA, even that didnt work. Also when I comment on these lines, everything starts working. No 404 from Server. One more thing, I am wrapping these two lines inside Thats correct right? are you using LiteSpeed webserver ? did you see geo country code as my screenshot , in your phpinfo page ? try RewriteCond % ENV:GEOIP_COUNTRY_CODE IN [NC] RewriteRule . - [F,L] if you are from India , this rule should make page 403 error , does this work ? Hi Thank you so much, Everything seems to be working fine, Ill test and will let you know if any issue comes up Hi, sure , please keep me posted. Best regards,



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



Reference