Expand my Community achievements bar.

SOLVED

Redirect rule based on accept language

Avatar

Level 2

Hi,

 

I am trying to redirect the home page of a website based on the browser language of the user. For doing this, I have put in the following rule which is not working.-

 

#Redirect for Portuguese language based on HTTP header
RewriteCond %{HTTP:Accept-Language} pt [NC]
RewriteCond %{HTTP_HOST} xxx.lat [NC]
RewriteRule ^(.*)$ https://www.xxx.lat/pt$1 [R=301,L]

Is there any issue with the way the accept language header is used? Can anyone please point out the issue here? 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
5 Replies

Avatar

Community Advisor

Can you check if header

HTTP:Accept-Language

is set and propagate to apache

 

if not then it will not work

 

arunpatidar_0-1665493950111.png

 

You can test here https://htaccess.madewithlove.com/ 

 

 



Arun Patidar

Avatar

Level 2

Thanks @arunpatidar for your reply. I am adding this rule in my dispatcher. Can you give any direction how to set and propagate this to apache, as I am a bit new to this area?

Avatar

Correct answer by
Community Advisor

Avatar

Level 2

Many thanks @arunpatidar . These clientheaders (including 'accept-language') are already allowed/included under /clientheaders. Still, it is not working.

The second link shared is for response headers, which i think wont be required because I want to access the request header.

 

Do you think there is any error with the format or case? 

On second thought, is this the right approach to handle language based redirects? should it be done through js scripts in your view?

Avatar

Community Advisor

We are managing this at CDN level, we have rules to redirect to users language home page based on language and country if user is coming from different geographical area.

You can manage this at CDN or at apache. Using javascript may help if you put in head section and do a redirect before page completely loaded.



Arun Patidar