How to use LiteSpeed Cache (LSCache) for non-WordPress websites
This guide explains how to use LiteSpeed Cache (LSCache) to speed up websites that are not built with WordPress, such as Joomla, OpenCart, PrestaShop, Drupal, Laravel or a custom PHP site. EgWeb hosting runs on LiteSpeed Web Server, which has a page cache built into the server. When a page is cached, LiteSpeed serves it directly without running PHP or the database, so pages load much faster and use far fewer resources.
Option 1: Use the official LSCache plugin for your platform (recommended)
LiteSpeed publishes free cache plugins or extensions for several popular platforms, including Joomla, OpenCart, PrestaShop, Drupal, Magento, Laravel, XenForo and MediaWiki. They know which pages are safe to cache and purge the cache automatically when you edit content.
- Search for "LSCache" plus your platform name on the LiteSpeed website or your platform's extension store.
- Take a backup, then install the plugin from your site's admin panel like any other extension.
- Enable it and keep the default settings first. Test the site as a visitor and as a logged-in user, then tune the settings.
Option 2: Simple rule-based cache in .htaccess
For a simple PHP or static-like site with no logins or cart, you can turn on caching with a few lines at the top of the .htaccess file in public_html:
<IfModule LiteSpeed>
CacheLookup on
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(GET|HEAD)$
RewriteCond %{HTTP_COOKIE} !(loggedin|PHPSESSID) [NC]
RewriteCond %{REQUEST_URI} !^/(admin|login|cart|checkout|account) [NC]
RewriteRule .* - [E=Cache-Control:max-age=120]
</IfModule> This caches public pages for 120 seconds, and skips logged-in visitors, sessions and private pages. Change max-age (in seconds) and the excluded paths to suit your site.
.htaccess before editing.Step 3: Check that the cache works
Run this from your computer or the cPanel Terminal twice:
curl -sI https://example.com/ | grep -i x-litespeed-cache The first request may show x-litespeed-cache: miss; the second should show hit. You can also see this header in the browser: press F12, open Network, reload, and click the page request. If the header never appears, contact support to confirm caching is enabled for your account.
Clearing the cache
- With a plugin: use its Purge All button.
- With manual rules: cached pages expire after
max-age. To clear everything from your own PHP code, send this header from any page:
<?php header('X-LiteSpeed-Purge: *'); ?> Common problems
- Visitors see someone else's cart or name: a private page is being cached. Remove the rules immediately, purge, and exclude that page or cookie.
- Changes do not appear: purge the cache or lower
max-age. - Always "miss": the site sets a session cookie for every visitor, so the
PHPSESSIDcondition skips caching. Use the platform plugin, which handles this properly. - 500 error after editing .htaccess: restore the backup copy and see how to fix a 500 error.
Frequently asked questions
Is LSCache free on EgWeb hosting?
Yes, it is part of the LiteSpeed server on our shared hosting. The official plugins are free too.
Can I use LSCache with Cloudflare?
Yes. LSCache works on the server and Cloudflare works in front of it. Just remember to purge both after big changes.
Will caching fix a slow database or heavy plugin?
It hides the problem for cached pages, but uncached pages (cart, admin) stay slow. Fix the root cause too.