I need to send data from $_SESSION
from PHP file to .htaccess for setup Vary variable for setting LiteSpeed cache.
PHP script example:
<?php $lang = $_SESSION['lang'];?>
.htaccess example
...
<IfModule LiteSpeed>
CacheLookup public on
CacheLookup private on
RewriteRule .* - [E=cache-control:max-age=604800]
RewriteRule .* - [E=cache-control:vary=**!!!HERE I NEED TO HAVE $lang value!!!**]
</IfModule>
...
I already tried these ways:
"RewriteCond %{HTTP_COOKIE} (.*) [NC]"
. But I will have also private data which I can't set in the cookies. So this approach is not very good.(putenv("PROVARY=".$_SESSION['lang']);)
. But it does not work. Because they die at the end of the request.HTTP_SESSION
. I found this name of a module but didn't find info about how it works or even how to use it. Is it possible to get $_SESSION
variables from .htaccess directly? If yes, show a working example of how it works.
It's never a good idea to cache pages, based only on session vars - especially, if the content only varies based on the language stored inside the session. Even LiteSpeed say, to don't do so
However, you could store the language additonally inside a cookie and vary on the cookie value.
For further projects I would recommend to store the language inside the uri (example.com/en/...
, example.com/de/...
)