AEMAaCS Dispatcher | URL rewrite based on cookie value | Community
Skip to main content
Level 5
August 17, 2023
Solved

AEMAaCS Dispatcher | URL rewrite based on cookie value

  • August 17, 2023
  • 3 replies
  • 1799 views

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.
Best answer by pradeepdubey82

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

3 replies

sherinregi-1
Community Advisor
Community Advisor
August 17, 2023

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

 

 

Ritesh_Mittal
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
August 17, 2023

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

Rohan_Garg
Community Advisor
Community Advisor
August 17, 2023

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.

pradeepdubey82AuthorAccepted solution
Level 5
August 18, 2023

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