Expand my Community achievements bar.

SOLVED

AEMAaCS Dispatcher | URL rewrite based on cookie value

Avatar

Level 6

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

1 Accepted Solution

Avatar

Correct answer by
Level 6

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

View solution in original post

4 Replies

Avatar

Community Advisor

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

 

 

Avatar

Community Advisor

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

Avatar

Community Advisor

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.

Avatar

Correct answer by
Level 6

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