Header always edit Set-Cookie not working
I am using Apache 2.4.6 on an up-to-date installation of CentOS 7.9. I have tried all variations of setting a header like below (adding/removing quotes, changing the regular expression, etc.) but the Set-Cookie header is never modified when sent to the user. Every article I find trying to accomplish this says it works but it just does not work for me.
Header always set TestBefore 1
Header always edit Set-Cookie ^(.*)$ "$1; SameSite=Strict; Secure"
Header always set TestAfter 1
Both the before and after headers are sent but the Set-Cookie header is never modified. Any idea what the issue could be?
Solution 1:
Your Set-Cookie header is being set in the onsuccess
condition, not the always
condition. Those are different sets. You need
Header onsuccess edit Set-Cookie (.*) "$1; SameSite=Strict; Secure"
Or just leave out onsuccess
, since it's the default. See Header.