AEMAaCS Dispatcher | URL rewrite based on cookie value | Community
Skip to main content
Level 5
Aug 17, 2023 10:03 AM UTC
Solved

AEMAaCS Dispatcher | URL rewrite based on cookie value

Hi All,

 

I have to redirect page A to page B if cookie is not present. If cookie is present then this redirection will not happen.

I need to redirect to page B before request reaches to AEM server. 

How can we do this on dispatcher?

 

Any pointers highly appreciated.

 

Thanks,

Pradeep

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
pradeepdubey82Accepted solution
Level 5
Aug 18, 2023 4:43 AM UTC

Hi All,

 

Finally it worked

 

RewriteCond %{HTTP_COOKIE} !mycookie
RewriteRule ^/(.*)/test-project/page1(.*?) /$1/page3 [QSA,L,R,NE]
RewriteRule ^/(.*)/test-project/page2(.*?) /$1/page3 [QSA,L,R,NE]

 

Thanks,

Pradeep

4 replies

Rohan_Garg
New Participant
Aug 17, 2023 12:46 PM UTC

You can use the usual rewrite module of the Apache to do so - 

Use mod_rewrite with a RewriteCond that checks the HTTP_COOKIE variable and then rewrite as desired, for example:

RewriteEngine on
RewriteCond %{HTTP_COOKIE} cookie=([a-zA-Z]+)
RewriteRule .* http://mydomain.com/NEW-LOCATION/%1 [R=301,L]

Here the value of cookie can be any custom value.

Translate
pradeepdubey82AuthorAccepted solution
Level 5
Aug 18, 2023 4:43 AM UTC

Hi All,

 

Finally it worked

 

RewriteCond %{HTTP_COOKIE} !mycookie
RewriteRule ^/(.*)/test-project/page1(.*?) /$1/page3 [QSA,L,R,NE]
RewriteRule ^/(.*)/test-project/page2(.*?) /$1/page3 [QSA,L,R,NE]

 

Thanks,

Pradeep

Translate
Ritesh_Mittal
New Participant
Aug 17, 2023 11:22 AM UTC

Hi @pradeepdubey82 ,

 

Please try below-

 

RewriteCond %{HTTP_COOKIE} mycookie
RewriteRule .* /page-A.html?redirectTo=/page-B.html [QSA,L,R,NE]

 

Where mycookie is the cookie name.

 

Thanks,

Ritesh Mittal

Translate
sherinregi-1
New Participant
Aug 17, 2023 11:06 AM UTC

Hi @pradeepdubey82 

You can try with apache rewrite engine . Tweak the below code and can try 

RewriteEngine On
RewriteCond %{HTTP_COOKIE}   ^.*COOKIENAME=COOKIEVALUE.*$
RewriteRule ...

 

Also another link that might be useful for you here 

https://stackoverflow.com/questions/6021552/check-cookie-and-redirect-with-apache

 

 

Translate