LiteSpeed Cache & WordPress


Our servers have been running the LiteSpeed Web Server for almost six years now and one of the lesser known but most powerful features of it is its caching. LiteSpeed cache is available on our servers although it is disabled on all domains by default. Enabling it globally just isn’t practical or wise because there is a lot of content that doesn’t need to be cached or shouldn’t ever be cached.

LiteSpeed cache can be used to cache your PHP scripts and thus speed up their load time significantly. This can be very beneficial if your site receives consistent traffic although even low traffic sites can see some benefits. The cache can be enabled and configured by means of some mod_rewrite rules in your .htaccess file. Below is a common example that can be used to cache WordPress:

<IfModule LiteSpeed>
CacheEnable public /
RewriteEngine on
RewriteCond %{REQUEST_URI} !^(wp-admin|wp-login.php|wp-cron.php)
RewriteRule .* - [E=Cache-Control:max-age=120]

This will cache everything except the wp-admin.php, wp-login.php, and wp-cron.php scripts for two minutes. With this enabled the first time a page is visited it will load normally. If requested again within two minutes the page will be served much quicker from cache. To confirm whether or not a page was served from cache you can view the response headers using the Firefox developer tools or any other tool that will display the them. Here you can see a hit that was not cached:


Now you can see a hit that was cached:


The difference is that a cached hit will have the x-litespeed-cache header sent as “hit” as you can see in the second screenshot. While this example was for WordPress, LiteSpeed cache can be used for any script you wish to configure it for using customized mod_rewrite rules. LiteSpeed has some examples posted on their forums here. You can disregard any server related configuration items as these are already taken care of. Your only concern would be the mod_rewrite rules which control the implementation of the caching on your domain. Try it out on your own WordPress or other script and let us know what you think!

Leave a Reply