LSCache is not only for WordPress. LiteSpeed Web Server can cache any page through rules in .htaccess. For simple PHP sites, landing pages or apps without an official LSCache plugin, a few lines can make pages load in milliseconds and cut server load.
Before you start
- A site on MdmHost (LiteSpeed is on every server).
- A list of pages that must never be cached: login, admin, cart, checkout, account and any page with personal data.
- If your app has an official LSCache plugin (WordPress, Joomla, Magento, PrestaShop, OpenCart, Drupal, XenForo, MediaWiki), use the plugin instead; it handles purging for you.
Basic cache rules
Add these lines at the top of the site's .htaccess:
<IfModule LiteSpeed>
CacheLookup on
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(GET|HEAD)$
RewriteCond %{HTTP_COOKIE} !(loggedin|session|cart) [NC]
RewriteCond %{REQUEST_URI} !^/(admin|login|cart|checkout|account) [NC]
RewriteRule .* - [E=cache-control:max-age=600]
</IfModule>What each line does:
CacheLookup onlets LiteSpeed serve cached copies.- Only GET and HEAD requests are cached; form posts are not.
- Visitors with login, session or cart cookies always get a fresh page. Adjust the cookie names to the ones your app uses.
- Admin, login, cart, checkout and account URLs are excluded.
max-age=600keeps pages for 10 minutes.
Warning: Caching a page with personal data, such as an account page, can show one visitor's details to another. Exclude every private URL and every cookie that marks a logged-in user before going live.
Test the cache
- Open a public page in a private browser window.
- Press F12, open Network, reload twice and click the page request.
- The response headers should show
x-litespeed-cache: hiton the second load.missmeans the page was just stored; no header means the rule did not match. - Log in to your app and confirm private pages show no
hitheader.
Purging the cache
- Pages expire automatically after the TTL.
- Your application can send the response header
X-LiteSpeed-Purge: *after content changes to clear the whole cache. - Customers can also flush from cPanel → Advanced → LiteSpeed Web Cache Manager where available (see LiteSpeed Web Cache Manager).
Vary the cache by device
If your site shows different HTML to mobile visitors, add a separate cache for mobile:
RewriteCond %{HTTP_USER_AGENT} "Mobile|Android|iPhone" [NC]
RewriteRule .* - [E=Cache-Control:vary=ismobile]Responsive sites that serve the same HTML to all devices do not need this.
Troubleshooting
Always "miss"
The page sets a cookie on every request (for example a PHP session started on every page), or sends Cache-Control: no-cache. Start sessions only where needed.
Visitors see stale content
Lower the TTL or purge after updates. Rules and their behaviour are covered more broadly in .htaccess on LiteSpeed.
Frequently asked questions
Is this as good as the WordPress plugin?
For simple sites, yes. The plugins add smart purging when content changes, which rules alone cannot do.
Does this cache images and CSS?
Static files are already served efficiently and cached by browsers. These rules are for HTML pages generated by PHP.
What TTL should I choose?
Ten minutes to an hour suits most brochure sites. Pages that rarely change can use several hours; news pages should use less.
