Apache mod_cache: Vary cookie based cookie

I am currently using mod_cache to cache page details of a web application.

I have a Vary cache based on User-Agent and Accept-Language, as there are different payloads for these situations.

Vary: User-Agent, Accept-Language

We plan to have information on specific regions on each page, but it is here that we are trying to define our caching strategy.

We have a cookie that continues to indicate the region to which we are attached, but obviously the cache does not depend on this cookie.

Is it possible to vary depending on the value for certain cookies or headers in general? (Note that I say some cookies, since we do not want the session identifier to encounter this) - something like a regular expression matches this:

location=(.+?);
+3
source share
1 answer

This is possible with Apache. It can parse the cookie value and pass it into a custom header, then you need to change this header:

# Set languageC cookie value to environment variable "siteLanguage"
RewriteCond %{HTTP_COOKIE} ^.*lunetics_locale.*$ [NC]
RewriteCond %{HTTP_COOKIE} (?:^|;\s*)lunetics_locale=([^;]*) [NC]
RewriteRule ^(.*)$ - [env=siteLanguage:%1]

# If no languageC cookie present. Set "siteLanguage" environment variable to "en"
RewriteCond %{HTTP_COOKIE} !^.*lunetics_locale.*$ [NC]
RewriteRule ^(.*)$ - [env=siteLanguage:en]

# Set enviroment variable "siteLanguage" value to custom header "SiteLanguage"
RequestHeader set X-Language "%{siteLanguage}e" env=siteLanguage

and add Vary X-Languageto the response headers. I'm not sure if this is the best way, I have related questions and problems with this: Is it possible to change page caches (in order to have cache versions) with the same URL and a different value cookie (language)?

+1
source

All Articles