• Resolved smoke_29

    (@daniel290881)


    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 ??

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter smoke_29

    (@daniel290881)

    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", "\n", "\t", " ", "-", "_"), 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("https://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;
    }

    Would it be possible with this?

    Thread Starter smoke_29

    (@daniel290881)

    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’])}}]

    • This reply was modified 4 years, 10 months ago by smoke_29.
    Thread Starter smoke_29

    (@daniel290881)

    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

    • This reply was modified 4 years, 10 months ago by smoke_29.
    Plugin Support qtwrk

    (@qtwrk)

    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,

    Thread Starter smoke_29

    (@daniel290881)

    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?

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    No really , if incoming visitor are guest user, they can be all public as well.

    Best regards,

    Thread Starter smoke_29

    (@daniel290881)

    Tried this but doesn’t work ??

    <IfModule LiteSpeed>
    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]
    </IfModule>

    Plugin Support qtwrk

    (@qtwrk)

    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

    View post on imgur.com

    Best regards,

    Thread Starter smoke_29

    (@daniel290881)

    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 didn’t 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!

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    No, the rewriterule and vary will be set before you hit PHP, and if it hits cache, PHP code won’t be executed, that’s 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,

    Thread Starter smoke_29

    (@daniel290881)

    I am on a shared hosting. I have just opened a ticket there but i think they wont do it. Then didn’T enable crawler too yesterday .

    Plugin Support qtwrk

    (@qtwrk)

    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,

    Thread Starter smoke_29

    (@daniel290881)

    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 ??

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    Glad to know it works for you ??

    Best regards,

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Some questions to Vary Cache by Country’ is closed to new replies.