Redirects do not work with x-aem-client-country header | Community
Skip to main content
Guglielmo89
Level 2
November 15, 2024

Redirects do not work with x-aem-client-country header

  • November 15, 2024
  • 1 reply
  • 932 views

Hi everyone,

 

I have a website in AEM Cloud, with custom CDN Imperva (that should be forwarding the header, since is exposing it also in the response section) and my goal is to redirect users based on their country, to the correct site.

Here is what I've done:

  • Added "X-Aem-Client-Country" both in the clientheaders.any and the site.farm file. In the last one is in the /cache /headers section
  • Added "Header set Vary "X-Aem-Client-Country" in the site.vhost file
  • Added custom rewrites in the rewrite.rules file. Here is an example:
    RewriteCond %{REQUEST_URI} ^/?$
    RewriteCond %{HTTP:X-Aem-Client-Country} ^US$ [NC]
    RewriteRule ^.*$ /en-us [R=301,L]
  • As a "default" page I've left a "country choice" page that should hit when the country code is not among the ones specified in the rewrite.rules file

I've tried also with the name of the header in uppercase or lowercase but it changes nothing.

 

Maybe I'm forgetting something, but the situation right now is that the site is not redirecting to specific homepages when the "root" URL is opened (to be clear: only the site with the domain www.site.com should redirect to www.site.com/en-us if the user is from USA).

 

Someone has a suggestion about this matter? 

 

Thank you!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

MukeshYadav_
Community Advisor
Community Advisor
November 15, 2024

Hi @guglielmo89 ,

Rules seems good however can you give try by making it to uppercase like below

RewriteCond %{REQUEST_URI} ^/?$ RewriteCond %{HTTP:X-AEM-CLIENT-COUNTRY} ^US$ RewriteRule ^/?$ /content/${CONTENT_FOLDER_NAME}/us/en/home.html [PT,L]

and header in lowercase

/headers { "Cache-Control" "Content-Disposition" "Content-Type" "Expires" "Last-Modified" "X-Content-Type-Options" "x-aem-client-country" "x-aem-client-continent" }

Also, under my.vhost, added Vary header to invalidate cache when country header changes if required

<VirtualHost *:80>
<Directory>
# Vary header to invalidate cache when client country changes
Header set Vary "x-aem-client-country"
</Directory>

Thanks

Guglielmo89
Level 2
November 18, 2024

Hi, thank you for your suggestions but I've already tried to add those configurations with uppercase/lowercase and tried also other combinations. None of them had success