Expand my Community achievements bar.

SOLVED

Dispatcher redirect rule | Multiple languages in header

Avatar

Level 6

Hi Folks,

 

I need to define redirect rule to handle where one set of languages to redirect to site.com/en.html while other set of languages to redirect to site.com/fr.html

for example cn, de, fr to redirect site.com/en.html

while 

it, ja, zh to redirect site.com/fr.html.

 

How can I define such rule?

 

Is it possible like?

 

RewriteCond %{HTTP:Accept-Language} cn,de,fr [NC]
RewriteCond %{HTTP_HOST} site.com/en [NC]

RewriteCond %{HTTP:Accept-Language} it,ja,zh[NC]
RewriteCond %{HTTP_HOST} site.com/fr[NC]

 

Any help is highly appreciated.

 

Thanks,

Pradeep

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

May be you can try something as below

RewriteCond %{HTTP:Accept-Language} ^(en|es|fr|kk) [NC]

Regards

https://www.albinsblog.com

View solution in original post

9 Replies

Avatar

Level 2

You can use  Rewrite rules on Apache to redirect your HTTP request 

Apache <-> Dispatcher <-> publisher

RewriteRule site.com/en.html /content/site/en.html [Your AEM content page path to allow requests from the dispatcher ]

 

Avatar

Level 6

I need to handle one set of languages to redirect to en version of the site. 2nd set of languages to redirect fr version of the site.

How to handle this scenario in dispatcher?

Avatar

Community Advisor

You can write Apache rewrite rules for each individual language to have redirect to appropriate location

Avatar

Level 6

How to define rule to handle multiple languages in one rule ? So that I can club all languages in two rules to make this simple. 

Otherwise we have to write 100 rules for 100 languages. This solution will be complex to maintain.

Avatar

Correct answer by
Community Advisor

May be you can try something as below

RewriteCond %{HTTP:Accept-Language} ^(en|es|fr|kk) [NC]

Regards

https://www.albinsblog.com

Avatar

Level 6

This is the redirect rule

<IfModule mod_rewrite.c>
#Redirect for English language based on HTTP header
RewriteCond %{HTTP:Accept-Language} ^(en|cn|de|fr) [NC]
RewriteCond %{HTTP_HOST} localhost [NC]
RewriteRule ^(.*)$ http://www.localhost:8080/content/we-retail/us/es$1 [R=301,L]
</IfModule>

 

this is the clientheaders

/clientheaders
{
# Forward all request headers that are end-to-end. If you want
# to forward a specific set of headers, you'll have to list
# them here.
"CSRF-Token"
"X-Forwarded-Proto"
"referer"
"user-agent"
"authorization"
"from"
"content-type"
"content-length"
"accept-charset"
"accept-encoding"
"accept-language"
"accept"
"host"
"max-forwards"
"proxy-authorization"
"proxy-connection"
"range"
"cookie"
"cq-action"
"cq-handle"
"handle"
"action"
"cqstats"
"depth"
"translate"
"expires"
"date"
"dav"
"ms-author-via"
"if"
"lock-token"
"x-expected-entity-length"
"destination"
"PATH"
}

 

When I am hitting the URL 

http://localhost:8080/content/we-retail/us/en.html

 

As per the en language rule It should redirect to http://localhost:8080/content/we-retail/us/es.html

Which is not happening.

Am I missing anything here?

 

 

Avatar

Level 6

I have checked dispatcher logs. Nothing much I got from logs.

 

Below rewrite rule is not working

 

RewriteCond %{HTTP:Accept-Language} ^(en|cn|de|fr)/.*$ [NC]
RewriteCond %{HTTP_HOST} dev-test.site.com [NC]
RewriteRule ^(.*)$ http://dev-test.site.com/tc$1 [R=301,L]