> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Enabling caching on Turbo Web Hosting

> Enable caching on Turbo servers by adding LiteSpeed directives to your .htaccess file - boost site speed and control cache duration.

This article describes how to enable caching on the following Turbo hosting packages:

* Turbo Velocity and Turbo Nitro Web Hosting accounts.

* Turbo Managed VPS.

* Turbo Managed Dedicated server.

## Enabling caching

By default, caching is disabled on Turbo accounts. To enable caching for your account, you use directives in an *.htaccess* file. These directives enable you to control precisely which types of content the Turbo server caches, and for how long. You should create the *.htaccess* file in the base folder for the application that you want to cache.

<Tip>
  You can use multiple *.htaccess* files in different directories to specify different cache control settings for each application.
</Tip>

The following sample configuration demonstrates how to enable caching on a Turbo account:

```
<IfModule LiteSpeed>
    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} ^GET|HEAD$
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteCond %{REQUEST_URI} !login|admin|register|post|cron
    RewriteCond %{QUERY_STRING} !nocache
    RewriteRule .* - [E=Cache-Control:max-age=300]
</IfModule>
```

<Warning>
  **Important**

  * These caching configuration directives must be at the **top** of the *.htaccess* file.

  * You only need to include the **HTTP\_HOST** configuration line if you host more than one domain in the *public\_html* directory (such as your primary domain and a subdomain). Replace ***example.com*** with the domain name for which you want to enable caching.

  * If you want to enable caching for multiple domains, separate them with the pipe ('|') symbol. For example:

  ```
  RewriteCond %{HTTP_HOST} ^example.com|example.net|example.org [NC]
  ```
</Warning>

Let's go through this example configuration line by line:

* The first line checks to make sure the web server is running LiteSpeed.
  > 📘 Note
  >
  > Strictly speaking, you do not have to use this line (and its corresponding line at the end of the file), but it is good practice to do so, particularly if you use the *.htaccess* file on a different server in the future.

* The second line turns on URL rewrite functionality. Turbo servers use rewrite conditions and rules to control caching behavior.

* The third, fourth, and fifth lines use **RewriteCond** directives to specify what should and should not be cached. The REQUEST\_METHOD condition instructs the server to cache GET and HEAD requests, but not POST requests. The REQUEST\_URI condition, because it begins with an exclamation mark ( **!** ), instructs the server to **not** cache any page whose URL contains *login*, *admin*, *register*, *post*, or *cron*.
  > 📘 Note
  >
  > To add additional strings to the REQUEST\_METHOD or REQUEST\_URI conditions, use the pipe symbol ( **|**) to separate them.

* The **QUERY\_STRING** configuration line enables you to see the non-cached version of any page by adding **nocache** to a [query string](https://en.wikipedia.org/wiki/Query_string) in the URL. For example, to view the non-cached version of *[http://example.com/mypage](http://example.com/mypage)*, you could add *?any\_field=any\_value\&nocache* to the end of the URL.

* The **RewriteRule** directive actually sets the cache duration. In this example, pages are cached for five minutes (300 seconds).

<Tip>
  To verify that caching is working correctly on your account, you can examine the raw HTTP headers sent between the browser and web server. (To do this, use a browser plugin that displays the raw headers such as Live HTTP headers for Mozilla Firefox, or the Developer Tools feature in Google Chrome.) When content is served from the cache, the server adds the following line to the HTTP response header:

  ```
  X-LiteSpeed-Cache: hit
  ```

  If you do not see this line in the HTTP response header from the server, then the content was not served from the cache.
</Tip>

### Caching and static content

Turbo accounts do not cache static content, such as audio and image files, on the web server. This type of content is cached by client web browsers instead. However, you can specify how long web browsers should cache your static content by using the **ExpiresByType** directive in the *.htaccess* file. For example, the following lines instruct web browsers to cache MP3 files for one year (31557600 seconds) and GIF files for 30 days (2592000 seconds):

```
ExpiresByType audio/mp3 A31557600
ExpiresByType image/gif A2592000
```

For more information about the **ExpiresByType** directive, please visit [https://httpd.apache.org/docs/2.4/mod/mod\_expires.html#ExpiresByType](http://httpd.apache.org/docs/2.4/mod/mod_expires.html#ExpiresByType).

## More information

For detailed information about caching behavior on a server running LiteSpeed, please visit [http://www.litespeedtech.com/support/wiki/doku.php?id=litespeed\_wiki:litespeed:cache](http://www.litespeedtech.com/support/wiki/doku.php?id=litespeed_wiki:litespeed:cache).
