Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
litespeed_wiki:cache:developer_guide:rewrite_rules [2018/05/29 21:14] George Wang [Cache-Vary] |
litespeed_wiki:cache:developer_guide:rewrite_rules [2020/07/31 19:36] (current) Lisa Clarke Redirect to new Documentation Site |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Rewrite Rules ====== | + | ~~REDIRECT>https://docs.litespeedtech.com/lscache/devguide/controls/~~ |
- | Control cache behavior by setting environment variables. \\ | + | |
- | NOTE: X-LiteSpeed-* cache related response headers will overrule any storage settings, if applicable.\\ \\ | + | |
- | 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. \\ | + | |
- | + | ||
- | Disable auto flush private cache by POST request: \\ | + | |
- | ''RewriteRule .* - [E=cache-control:no-autoflush]'' \\ | + | |
- | + | ||
- | 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-Vary ===== | + | |
- | 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'' \\ | + | |
- | Makes cache varying on cookie value of ''isloggedin''. | + | |
- | + | ||
- | Another type of cache vary can be controlled without involving a cookie, the vary value is set directly via ''cache-control'' environment with special value ''vary=<vary_value>'' . | + | |
- | Examples: \\ | + | |
- | Cache response from browser with "mobi" signature as cache copy for mobile device for 5 minutes (300 seconds). \\ | + | |
- | ''RewriteRule .* - [E=cache-control:max-age=300]'' \\ | + | |
- | ''RewriteRule HTTP_USER_AGENT mobi [E=cache-control:vary=ismobile]'' \\ \\ | + | |
- | + | ||
- | **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]'' \\ \\ | + | |
- | + | ||
- | **Login Conflicts** \\ | + | |
- | If there are multiple web applications used for a single site, different cache varies should be used for login purposes to prevent cache conflicts. More information on this can be found **[[litespeed_wiki:cache:common:logged-in-cookie-conflicts|here]]**. | + |