0

We are implementing an Apache (Apache 2.4) server and we want to set expiration date for cookies. In the configuration file, we used the command like this

Header set Set-Cookie testcookie=%{UNIQUE_ID}e "expr=-z %{req:Cookie}"
Header set Cache-Control "max-age=7200, public"
Header set Expires "Sat, 21 Apr 2018 17:00:00 GMT"

The expiration date is not being set. In the cookie expires field it says "When the browsing session ends"

Except the code above, we have also tried the commands in htaccess file, the code is like this:

<IfModule mod_expires.c>
ExpiresActive On 
ExpiresDefault "access plus 1 day"
ExpiresByType image/x-icon "access plus 1 day"
ExpiresByType image/gif "access plus 1 day"
ExpiresByType image/png "access plus 1 day"
ExpiresByType image/jpg "access plus 1 day"
ExpiresByType image/jpeg "access plus 1 day"
ExpiresByType text/css "access 1 day"
ExpiresByType application/javascript "access plus 1 day"
ExpiresDefault "access plus 30 days"
</IfModule>

In addition, we have already load the the expires_module,cache_module, and unique_id module, the result still remains the same.

What else should we try?

Jeff
  • 21
  • 2
  • 11

1 Answers1

1

Adding Max-Age=<time-in-seconds> works for me.

Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; Max-Age=60" env=BALANCER_ROUTE_CHANGED

You can also use Expires=<date>

Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; Expires=Wed, 21 Oct 2019 07:28:00 GMT" env=BALANCER_ROUTE_CHANGED

Reference here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie

RASG
  • 5,988
  • 4
  • 26
  • 47