• Resolved webinvaders

    (@webinvaders)


    I have made plugin (“https://www.ads-software.com/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” don’t work anymore.

    They gave me access to the website (wp multisite setup) so we can debug the issue and I’ve tried to change how plugin works to make it compatible with your cache plugin but I can’t 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?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support qtwrk

    (@qtwrk)

    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,

    Thread Starter webinvaders

    (@webinvaders)

    Hi,
    this is scr.shot of headers https://nimb.ws/GLt9uq

    Site owner was setting up LiteSpeed cache plugin so i don’t really know what options are enabled.

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    yeah …

    I managed to reproduced it

    please try add this into user’s htaccess , anywhere before LSCWP rules

    <IfModule LiteSpeed>
    RewriteEngine On
    RewriteRule .* - [E=Cache-Control:vary=%{HTTP:CF-IPCountry}]
    </IfModule>

    tested and works on my case

    Best regards,

    Thread Starter webinvaders

    (@webinvaders)

    IT WORKS!
    I was trying to figure out why it’s not working for days… Thank you so much.

    Plugin Support qtwrk

    (@qtwrk)

    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 won’t execute any PHP function anymore , as the goal for using cache is to avoid running PHP

    and since page is cached , then your plugin won’t 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 user’s 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 country’s users get cache)

    Best regards,

    • This reply was modified 3 years, 7 months ago by qtwrk.
    Thread Starter webinvaders

    (@webinvaders)

    I can confirm the solution, After checking thoroughly it seems that works perfectly.
    Thanks again @qtwrk

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘wp_redirect() not working with LiteSpeed Cache on’ is closed to new replies.