• Resolved guyblueboat1

    (@guyblueboat1)


    Hi There,

    I’m struggling to implement vary cache on one of our sites based on the different variables of a cookie as below:

    RewriteCond %{HTTP_COOKIE} scwp_location=melbourne [NC]
    RewriteRule .? - [E=Cache-Vary:melbourne]
    
    RewriteCond %{HTTP_COOKIE} scwp_location=none [NC]
    RewriteRule .? - [E=Cache-Vary:melbourne]
    
    RewriteCond %{HTTP_COOKIE} scwp_location=darwin [NC]
    RewriteRule .? - [E=Cache-Vary:darwin]
    
    RewriteCond %{HTTP_COOKIE} scwp_location=sydney [NC]
    RewriteRule .? - [E=Cache-Vary:sydney]
    
    RewriteCond %{HTTP_COOKIE} scwp_location=perth [NC]
    RewriteRule .? - [E=Cache-Vary:perth]
    
    RewriteCond %{HTTP_COOKIE} !scwp_location [NC]
    RewriteRule .? - [E=Cache-Vary:null]

    Any indication as to what we’re doing wrong? Is it possible we’ve inserted it into ht access in the wrong place or are our declarations wrong?

    The page I need help with: [log in to see the link]

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

    (@qtwrk)

    Hi,

    if you want to vary on cookie , you should use

    E=Cache-Vary:my_cookie]

    where m_cookie is the cookie name , it will automatically differentiate based on cookie value

    on , from your code , you need to use

    [E=Cache-Control:scwp_location=%{ENV:LSCACHE_VARY_VALUE}+melbourne] 
    
    [E=Cache-Control:scwp_location=%{ENV:LSCACHE_VARY_VALUE}+darwin] 
    
    [E=Cache-Control:scwp_location=%{ENV:LSCACHE_VARY_VALUE}+sydney] 

    you will need %{ENV:LSCACHE_VARY_VALUE} to carry over the current/previous vary into next rule as well

    Best regards,

    Thread Starter guyblueboat1

    (@guyblueboat1)

    Right thanks @qtwrk

    So the full code to vary based on the cookie is the following?

    RewriteRule .? - [E=Cache-Vary:scwp_location]

    Or do I need the extra cache control declarations for each individual cookie value?
    Also where is the best place to insert this into the .htaccess file, above or below the automatic LScache section?

    Thread Starter guyblueboat1

    (@guyblueboat1)

    As a follow up, I tried using the following, it varied the cache only on the homepage but no where else:

    <IfModule LiteSpeed>
    RewriteEngine on
    CacheLookup on
    
    RewriteRule .? - [E=Cache-Vary:scwp_location]
    
    </IfModule>
    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    no , you don’t need extra control for each cookie value

    enable cache plugin , then add this line at top of your .htaccess, don’t add it inside of LSCWP block

    Best regards,

    Thread Starter guyblueboat1

    (@guyblueboat1)

    Perfect, that’s what I tried and what worked for me!

    Thanks for your help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Stuck with Vary Cache htaccess’ is closed to new replies.