This is an old revision of the document!


Rewrite Rules

Control cache behavior by setting environment variables.

Syntax:

RewriteRule url1 - [E=cache-control:value1,E=cache-control:value2]
RewriteRule url2 - [E=cache-vary:value1,E=cache-control:value2]

Environment variables can have the following keys
cache-control/cache-ctrl

Regular cache-control directives:
RewriteRule .* - [E=cache-control:max-age=300]
RewriteRule .* - [E=cache-control:private,max-age=300]

Flush private cache:
RewriteRule /flush_cache - [E=cache-control:flush]
You cannot flush the public cache through rewrite rules.

Append a vary string to a cache object key directly:
RewriteRule url2 - [E=cache-control:vary=vary_value]
This directly appends vary_value to a cache key and a CGI environment variable
example: cache-control:vary=ismobile

Cache objects vary based on cookie values, this has the same effect as the X-LiteSpeed-Vary response header, the difference is that it only applies for the current request and it is not persistently associated with that URL.

cache-vary:<cookiename>
For example: cache-vary:isloggedin

Examples:
Cache response for 5 minutes (300 seconds).
RewriteRule .* - [E=cache-control:max-age=300]
RewriteRule HTTP_USER_AGENT mobi [E=cache-control:vary=ismobile]

====
For xenforo and Magento under wp uri paths, use rewrite rules to set different default vary cookies.
For a cookie vary set by a rewrite rule, we will add an Environment variable, like LSCACHE_VARY_COOKIE
This needs to be set via a cache-vary environment variable. E=Cache-Vary:mycookie1 mycookie1 is the name of the cookie.
RewriteRule .? - [E=Cache-Vary:_my_custom_vary]^M
====

ESI
Rewrite Rules can also control the ESI engine for a request. To turn on the ESI engine for a request:
RewriteRule .* - [E=esi_on:1]

To turn off the ESI engine for a request:
RewriteRule .* - [E=esi_on:0]

  • Admin
  • Last modified: 2016/05/16 17:26
  • by Rob Holda