I am trying to set a cookie through dispatcher and I using the below header
Header set Set-Cookie "currentCountryNames=Indian; path=/"
It works fine with static value, but I need to get the dynamic value through CDN(cloudfront) by using header HTTP:CLOUDFRONT-VIEWER-COUNTRY-NAME .
I tried this then
Header set Set-Cookie "currentCountryName=%{HTTP:CLOUDFRONT-VIEWER-COUNTRY-NAME}; Path=/"
but it did not worked it is giving syntax error
Unrecognized header format %;
Solved! Go to Solution.
Hi @varun790
You can try
<Location "/your-path">
SetEnvIf CLOUDFRONT-VIEWER-COUNTRY-NAME "(.*)" COUNTRY=$1
Header always set Set-Cookie "country=${COUNTRY}; Path=/; Expires=Thu, 01 Jan 2023 00:00:00 GMT"
</Location>
Note: The SetEnvIf
directive requires the mod_setenvif
module to be enabled in Apache. Ensure that it is enabled in your Apache configuration. Additionally, this assumes that CloudFront is forwarding the CLOUDFRONT-VIEWER-COUNTRY-NAME
header to your origin server.
Yes in dispatcher config
@varun790 : I am not sure if CloudFront header be accessible in dispatcher layer like the way you are trying to access.
Is it not possible for you to set this cookie at CloudFront layer?
thanks.
Hi @varun790
You can try
<Location "/your-path">
SetEnvIf CLOUDFRONT-VIEWER-COUNTRY-NAME "(.*)" COUNTRY=$1
Header always set Set-Cookie "country=${COUNTRY}; Path=/; Expires=Thu, 01 Jan 2023 00:00:00 GMT"
</Location>
Note: The SetEnvIf
directive requires the mod_setenvif
module to be enabled in Apache. Ensure that it is enabled in your Apache configuration. Additionally, this assumes that CloudFront is forwarding the CLOUDFRONT-VIEWER-COUNTRY-NAME
header to your origin server.
Hi @varun790
You can set a cookie with the value of the HTTP:CLOUDFRONT-VIEWER-COUNTRY-NAME header using expr syntax:
<If "%{HTTP:CLOUDFRONT-VIEWER-COUNTRY-NAME} != ''"> Header expr Set-Cookie 'currentCountryName="%{HTTP:CLOUDFRONT-VIEWER-COUNTRY-NAME}"; Path=/' </If>
@varun790 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Views
Likes
Replies