Support » Plugin: LiteSpeed Cache » Not caching pages for specific users

  • Resolved Cri000


    We are using an affiliate platform that request us to install a code so the phone number or our pages must be hidden. Using the cache after the user navigates through pages the phones appears, so we need to exclude these users from cached pages.

    Is there a possibility to hide cached pages from users that come from a specific url?


Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Uniqe_Eric



    You may achieve this by setting cookie to those users and use vary to exclude from caching.


    Thread Starter Cri000


    Hello Eric,

    Thanks for the message. Can you tell me more details about what you mean by ”use vary”?

    Thank you again!

    Plugin Support LiteSpeed Lisa


    Hi, @cri000, I can give you a few more details.

    LSCache has the ability to create multiple variations of a page to be stored in the cache. These variations can be based on cookies. So, if you assign a particular cookie to the users who are coming in from that affiliate URL, then you can tell LSCache to create a cached copy of the page that is only for those people who have the cookie.

    In other words, you’ll have a copy without the phone number for your affiliate visitors, and you’ll have a copy with the phone number for everyone else.

    You’ll need some development skills to make it work. Once you’ve used your own code to set the cookie, you can use our API to create a cache variation based on that cookie. The function looks like this: LiteSpeed_Cache_API::vary_add($cookie), where $cookie is a string equal to the name of the cookie you’ve assigned. You can get more information on our wiki.

    Once this is done, it should work automatically. LSCache will know which version of the cached page to serve based on the visitor’s cookie.

    I hope this helps!

    Plugin Support LiteSpeed Lisa


    Hi, again @cri000

    We’ve been discussing this internally, and we have a better solution for you.

    You will still need to assign a cookie to the affiliate visitors (call it aff, for example) but you don’t need to use the API.

    To cache a separate copy for affiliate visitors, modify your .htaccess and add the following line:

    RewriteRule .* - [E="cache-vary:aff"]

    This will create a separate cache copy.

    On the other hand, if you don’t want to cache the pages at all for the affiliate visitors, that’s even easier. Forget about .htaccess and simply navigate to LiteSpeed Cache > Settings > Excludes from the WP dashboard, and enter aff into the Do Not Cache Cookies box. Save your changes.

    I hope this makes sense. Please let me know if you have any questions!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Not caching pages for specific users’ is closed to new replies.