Issues with cache and WHMCS

#1
Hi,

I tried using the LiteSpeed Cache on my WHMCS site, its using a WHMCS template as well.

So i was trying to enable cache on this, when i noticed some issues, like users not really getting logget out when pressing log out (it says log out, but when they hit login, they just get logged back in) and so on, it works like a charm without the LiteSpeed Cache..

this was my .htaccess file

Code:
<IfModule litespeed>
    CacheLookup on
    RewriteEngine on
    RewriteRule .* - [E=Cache-Control:no-autoflush]
    RewriteRule .* - [E=Cache-Vary:sb-login]
    RewriteCond %{ORG_REQ_URI} !/admin
    RewriteCond %{ORG_REQ_URI} !/supportboard
</IfModule>
I tried sooo many things, but nothing is working for me.

Site address is https://www.webgail.com

Im not sure what im missing here...

Thanks in advance,
Bo.
 
#2
Just a sidenote, i did try to not cache https://www.webgail.com/login and https://www.webgail.com/clientarea.php but didnt seem to work.

Im also using this code i found, doesnt really seem to speed much up though, or maybe its just me :)

Code:
<IfModule litespeed>
    CacheLookup on
    RewriteEngine On
    ## cache should be available for HEAD or GET requests
    RewriteCond %{REQUEST_METHOD} ^HEAD|GET$
    ## select which pages to cache
    RewriteCond %{HTTP_COOKIE} page_contain_cachetoken=yes
    # with other condition
    RewriteCond %{QUERY_STRING} !s=[a-fA-F0-9]{32}
    # excluding certain URLs
    RewriteCond %{REQUEST_URI} !/(login|clientarea|admin|register|submitticket|cron|image) \.php$
    # cache for 2 mins for php pages only
    RewriteRule .* – [L,E=Cache-Control:max-age=120]

    # for those not met above condition, enable private cache.
    RewriteCond %{REQUEST_METHOD} ^HEAD|GET$
    ## select which pages to serve from private cache
    RewriteCond %{HTTP_COOKIE} !page_contain_cachetoken=yes
    # with other condition
    RewriteCond %{QUERY_STRING} !s=[a-fA-F0-9]{32}
    # excluding certain URLs
    RewriteCond %{REQUEST_URI} !/(login|clientarea|admin|register|submitticket|cron|image) \.php$
    # private cache for however long set in cache policy for php pages only
    RewriteRule .* – [L,E=Cache-Control:max-age=120]
    RewriteRule .* – [L,E=Cache-Control:private]
</IfModule>
I get random hit- private or miss on frontpage , and any subpage i get litespeed not supported, like https://www.webgail.com/services/domain-names/

Tried this one

Code:
<IfModule litespeed>
    CacheLookup on
    RewriteEngine On
    RewriteRule .* – [L,E=Cache-Control:max-age=120]

    ### marker NOCACHE COOKIES start ###
    RewriteCond %{HTTP_COOKIE} sb-login
    RewriteCond %{REQUEST_URI} !/(admin|supportboard|login)
    RewriteCond %{REQUEST_URI} !/(register.php|clientarea.php)
    RewriteRule .* - [E=Cache-Control:no-cache]
    ### marker NOCACHE COOKIES end ###
</IfModule>
I had same issues, but page got alot faster, but i get some wierd redirects based on language and it never logs me out...

So what am i doing wrong?, someone can write me one and explain the issue? (im just guessing its something to do with not cache cookies and the login page/register and so on, but why its not working?
 
Last edited:

NiteWave

Administrator
#3
<IfModule litespeed> CacheLookup on RewriteEngine On RewriteRule .* – [L,E=Cache-Control:max-age=120] ### marker NOCACHE COOKIES start ### RewriteCond %{HTTP_COOKIE} sb-login RewriteCond %{REQUEST_URI} !/(admin|supportboard|login) RewriteCond %{REQUEST_URI} !/(register.php|clientarea.php) RewriteRule .* - [E=Cache-Control:no-cache] ### marker NOCACHE COOKIES end ### </IfModule>
how about
Code:
<IfModule litespeed>
    CacheLookup on
    RewriteEngine On
    RewriteRule .* - [E=Cache-Control:max-age=120]

    ### marker NOCACHE COOKIES start ###
    RewriteCond %{HTTP_COOKIE} sb-login [OR]
    RewriteCond %{REQUEST_URI} ^/(admin|supportboard|login) [OR]
    RewriteCond %{REQUEST_URI} ^/(register.php|clientarea.php)
    RewriteRule .* - [E=Cache-Control:no-cache]
    ### marker NOCACHE COOKIES end ###
</IfModule>
if there is logout.php, please add it after "login|", i.e.. "login|logout"

after change above cache rule, you may need purge all cache before new tests.
 
#4
how about
Code:
<IfModule litespeed>
    CacheLookup on
    RewriteEngine On
    RewriteRule .* - [E=Cache-Control:max-age=120]

    ### marker NOCACHE COOKIES start ###
    RewriteCond %{HTTP_COOKIE} sb-login [OR]
    RewriteCond %{REQUEST_URI} ^/(admin|supportboard|login) [OR]
    RewriteCond %{REQUEST_URI} ^/(register.php|clientarea.php)
    RewriteRule .* - [E=Cache-Control:no-cache]
    ### marker NOCACHE COOKIES end ###
</IfModule>
if there is logout.php, please add it after "login|", i.e.. "login|logout"

after change above cache rule, you may need purge all cache before new tests.
Hi, thanks, but it doesnt seem to work still..

One of the things is, i have a redirect based on language to
webgail.com/?language=english or webgail.com/?language=danish

This doesnt seem to work, sometime it change back to previous language you used on previous page...

I feel this is a nice tool, have some nice plugins for all kind of systems, why it dont have a generic LSConfig.php file that creates a .htaccess config file based kind of the same as all the nice plugins :)
 
Last edited:
#6
And also, while questioning,

Code:
RewriteCond %{HTTP_COOKIE} ^WHMCS.*
Will match any cookie that starts with WHMCSxxxxxxxxx, for example WHMCS4fedwq3 and WHMCS4ur8fhw3 ?
 

NiteWave

Administrator
#7
And also, while questioning,

Code:
RewriteCond %{HTTP_COOKIE} ^WHMCS.*
Will match any cookie that starts with WHMCSxxxxxxxxx, for example WHMCS4fedwq3 and WHMCS4ur8fhw3 ?
should remove ^, i.e.,
Code:
RewriteCond %{HTTP_COOKIE} WHMCS.*
or just
Code:
RewriteCond %{HTTP_COOKIE} WHMCS
have you set any cache policy in lsws web admin ?
 
#9
Is there a way this would work for mobile too? or does this automaticly work for it?

On pagespeed my mobile is 51, and computer 95, would love to increase the mobile speed too :)

I have added this code

Code:
<IfModule litespeed>
    CacheLookup on
    RewriteEngine On
    RewriteRule .* - [E=Cache-Control:max-age=120]

    ### marker MOBILE start ###
    RewriteCond %{HTTP_USER_AGENT} Mobile|Android|Silk/|Kindle|BlackBerry|Opera\ Mini|Opera\ Mobi [NC]
    RewriteRule .* - [E=Cache-Control:vary=ismobile]
    ### marker MOBILE end ###

    ### marker NOCACHE COOKIES start ###
    RewriteCond %{HTTP_COOKIE} sb-login [OR]
    RewriteCond %{HTTP_COOKIE} ^WHMCS.* [OR]
    RewriteCond %{REQUEST_URI} ^/(admin|supportboard|login|logout) [OR]
    RewriteCond %{REQUEST_URI} ^/(register.php|clientarea.php|logout.php|login.php)
    RewriteRule .* - [E=Cache-Control:no-cache]
    ### marker NOCACHE COOKIES end ###
</IfModule>
(this works)

but, im not sure if this is good for mobile, or need some other tweaks to work?
 

Pong

Administrator
Staff member
#10
google pagespeed insight will test many elements, not really focus on your pagespeed itself. Cache will help your TTFB, but nothing else. You should check more details on the score to see where got low scores, but they are most likely something else, not from the cache side.
 
Top