Wordpress LScache Plugin: wp_redirect() not working with LiteSpeed Cache on
Last Updated on: Wed, 15 Apr 2026 00:00:02 I have made plugin ( https://wordpress.org/plugins/wp-cloudflare-geoip-redirect/” ) that uses CloudFlare GeoIP service to redirect visitors from selected country to specified URL and it uses wp_redirect() function to execute redirection. One of the users have reported that after setting up LiteSpeed Cache plugin redirect using WP Cloudflare GeoIP Redirect dont work anymore. They gave me access to the website (wp multisite setup) so we can debug the issue and Ive tried to change how plugin works to make it compatible with your cache plugin but I cant find the way to do that. Is there a way to use outside redirection with LiteSpeed Cache plugin or do you have internal function / hook / api that i could use to make it work? Hi, Could you please specify some more information , and specially , how can I reproduce/trigger the issue ? I just set up a test site and make a redirection , ti seems working on me as you can see , it gives x-litespeed-cache-control: no-cache in my screenshot which means that request is not being cached Best regards, Hi, this is scr.shot of headers https://nimb.ws/GLt9uq Site owner was setting up LiteSpeed cache plugin so i dont really know what options are enabled. Hi, yeah ? I managed to reproduced it please try add this into users htaccess , anywhere before LSCWP rules RewriteEngine On RewriteRule . - [E=Cache-Control:vary=% HTTP:CF-IPCountry ] tested and works on my case Best regards, IT WORKS! I was trying to figure out why its not working for days? Thank you so much. Hi, oh , for your information , the issue here is because that : when user set redirection for country A , B , C ?etc , and not redirection for country X then if page is accessed by country X user first, then page will be cached , and as page is cached , it wont execute any PHP function anymore , as the goal for using cache is to avoid running PHP and since page is cached , then your plugin wont be able to detect the incoming visitor as PHP is not even running after that. and my trick is , RewriteRule . - [E=Cache-Control:vary=% HTTP:CF-IPCountry ] this rewrite rule , will tell webserver to create a different cache copy based on users country (provided by CF header) so it will become: country A -> get cache copy A (which is not cache in this case) country B -> get cache copy B (which is not cache in this case) country C -> get cache copy C (which is not cache in this case) ? ? Country X -> get cache copy X (which is now normal cache , since all other countries are no-cache and only this countrys users get cache) Best regards, I can confirm the solution, After checking thoroughly it seems that works perfectly. Thanks again @CacheCrawler
LiteCache Rush: Speed comes from using less, not from doing it faster
Reference