Skip to main content
Level 2
Feb 28, 2025 11:39 AM UTC

Problem with the AEM dispatcher rewrite rules

We are trying to set the cookie userRegionDispatcher when the dispatcher domain

(https://dev-aem-www.samplerm.org/home) gets loaded but that's actually not happening.

 

Please find the below rewrite rules from the dispatcher. 

We don't see any effect with the code(last line of the code piece) we have added.

Can someone help us out on the problem.

 

################################################# ## Rules for setting up userRegion cookie at the starting ################################################# # For 'us' or 'in' country codes RewriteCond %{HTTP:x-aem-client-country} ^(us|in)$ [NC] RewriteCond %{HTTP_COOKIE} !userRegion= [NC] RewriteRule ^ - [CO=userRegion=%1:31557600:/:Secure] # For 'mena' countries RewriteCond %{HTTP:x-aem-client-country} ^(DZ|DZA|BH|BHR|KM|COM|DJ|DJI|EG|EGY|IQ|IRQ|JO|JOR|KW|KWT|LB|LBN|LY|LBY|MA|MAR|MR|MRT|OM|OMN|PS|PSE|QA|QAT|SA|SAU|SO|SOM|SD|SDN|SY|SYR|TN|TUN|AE|ARE|YE|YEM)$ [NC] RewriteCond %{HTTP_COOKIE} !userRegion= [NC] RewriteRule ^ - [CO=userRegion=mena:31557600:/:Secure] ################################################# ## Trying to set up a userRegionDispatcher ################################################# RewriteRule ^ - [CO=userRegionDispatcher=samplecookie:31557600:/]

 

 

7 replies

Rohit_Utreja
Community Advisor
Community Advisor
Feb 28, 2025 12:48 PM UTC

Hi @shyamsundar ,

RewriteEngine On # Set userRegion and userRegionDispatcher together if not set RewriteCond %{HTTP:x-aem-client-country} ^(us|in)$ [NC] RewriteCond %{HTTP_COOKIE} !userRegion= [NC] RewriteRule ^ - [CO=userRegion=%1:31557600:/:Secure,CO=userRegionDispatcher=samplecookie:31557600:/] RewriteCond %{HTTP:x-aem-client-country} ^(DZ|DZA|BH|BHR|KM|COM|DJ|DJI|EG|EGY|IQ|IRQ|JO|JOR|KW|KWT|LB|LBN|LY|LBY|MA|MAR|MR|MRT|OM|OMN|PS|PSE|QA|QAT|SA|SAU|SO|SOM|SD|SDN|SY|SYR|TN|TUN|AE|ARE|YE|YEM)$ [NC] RewriteCond %{HTTP_COOKIE} !userRegion= [NC] RewriteRule ^ - [CO=userRegion=mena:31557600:/:Secure,CO=userRegionDispatcher=samplecookie:31557600:/] # Ensure userRegionDispatcher is set separately if missing RewriteCond %{HTTP_COOKIE} !userRegionDispatcher= [NC] RewriteRule ^ - [CO=userRegionDispatcher=samplecookie:31557600:/] # Ensure Dispatcher allows cookies <IfModule mod_headers.c> Header always edit Set-Cookie "(?i)^userRegionDispatcher=" "$0; SameSite=None" </IfModule>

Can you try with the below code?

Translate
BR, Rohit
Level 2
Feb 28, 2025 1:54 PM UTC

@rohit_utreja  Tried whatever dispatcher rewrite rule given. No luck bro.

Still I don't find the userRegionDispatcher cookie set in the dispatcher domain

 

 

Translate
Rohit_Utreja
Community Advisor
Community Advisor
Feb 28, 2025 4:05 PM UTC

try with below

RewriteRule ^ - [CO=userRegionDispatcher=samplecookie:31557600:/:Secure;SameSite=None]
Translate
BR, Rohit
AMANATH_ULLAH
Community Advisor
Community Advisor
Feb 28, 2025 3:53 PM UTC

@shyamsundar 

Can you try adding secure flag to the rule as below

RewriteRule ^ - [CO=userRegionDispatcher=samplecookie:31557600:/:Secure]

 

Translate
Amanath Ullah
Level 2
Mar 1, 2025 7:24 AM UTC

@amanath_ullah  - Tried this rewrite rule which did not work either 😞

 

RewriteRule ^ - [CO=userRegionDispatcher=samplecookie:31557600:/:Secure]

Translate
kautuk_sahni
Level 9
Mar 5, 2025 6:00 AM UTC

@shyamsundar Did you find the suggestions helpful? Please let us know if you need more information. If a response worked, kindly mark it as correct for posterity; alternatively, if you found a solution yourself, we’d appreciate it if you could share it with the community. Thank you!

Translate
Kautuk Sahni