Skip to content Skip to sidebar

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 -
- 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Long Nguyen 1 year, 3 months ago.

Assisted by: Long Nguyen.

Author Posts
March 20, 2024 at 3:01 am #15429338

salaC

Dear WPML Team,

I'm encountering an issue with my website, which is hosted on an Apache server, and I'm seeking your assistance. I've implemented the following rewrite rules to automatically redirect users based on their browser language settings to the appropriate language version of the site:

apache code:
RewriteCond %{HTTP:Accept-Language} ^zh-CN [NC]
RewriteCond %{REQUEST_URI} !^/cn/
RewriteRule ^$ /cn/ [L,R=301]

The goal is to redirect users with their browser language set to Simplified Chinese (zh-CN) to the Chinese version of the site. However, this setup has led to an infinite redirection loop when accessing the main domain.

Do you have any hooks or solutions to address this redirection loop issue? Or could you recommend a better practice to achieve browser-based redirection without causing loops?

Thank you for your assistance!

Sala

March 20, 2024 at 9:33 am #15430125

Long Nguyen
WPML Supporter since 02/2022

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi Sala,

Thank you for contacting WPML support, I’m happy to help you with this issue.

I suggest you use the feature "Automatic Redirect Based on Browser Language" of WPML. It setup in WPML > Languages. Refer documentation https://wpml.org/documentation/getting-started-guide/language-setup/automatic-redirect-based-on-browser-language/

If it doesn't help your case, you can try to use a custom JavaScript code to check the browser language and make a redirection. Please follow this topic https://stackoverflow.com/questions/71091601/js-redirect-based-on-browser-language
Note: I've not tested that code to confirm if it works with WPML.

If you are not able to accomplish this, I would recommend you contact one of our certified partners who will be more than happy to help you with this. In this link, you will find a list of our certified partners: https://wpml.org/contractors/

Thanks.

The topic ‘[Closed] Assistance Needed: Resolving Infinite Redirection Loop Based on Browser Language’ is closed to new replies.