Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to always redirect to the default language directory.
Solution:
Create a page for the root url of the website, WPML -> Languages -> Language URL format.
Create a redirect template and use it on the root url page.

Relevant Documentation:
https://wpml.org/documentation/getting-started-guide/language-setup/directory-default-language/#redirect-the-root-domain-to-the-default-language-directory

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.

This topic contains 6 replies, has 2 voices.

Last updated by krisztianK 1 year, 11 months ago.

Assisted by: Eran Helzer.

Author Posts
May 25, 2023 at 9:00 am #13714011

krisztianK

Dear Christopher,

Unfortunately, i have noticed the homepage default redirection is also incorrect! If I type hidden link does not redirect to hidden link - although the latter URL no longer returns a 404 error.

What should I do?

Thank you!

best regards,
Mihály

url balassi.JPG
May 26, 2023 at 9:19 am #13721577

Eran Helzer
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

Thank you for contacting support.

I see you selected to Use directory for default language, which is the first step to what you want to achieve.
The next step will be to add a page for the root url. That page will use a template that will immediately redirect to the home page, with the directory.

Please see the documentation for more details:
https://wpml.org/documentation/getting-started-guide/language-setup/directory-default-language/#redirect-the-root-domain-to-the-default-language-directory

If you have any more questions or need any further help, don't hesitate to ask.

May 26, 2023 at 11:07 am #13722645

krisztianK

Hi Eran,

Thank you! I have just followed your recommendation.

Unfortunately, nothing has changed.

I have created a template file in our child theme's folder according to the support article:

template-wpml-redirect.php

<?php
/*
	Template Name: WPML - Root redirect
    Source: https://wpml.org/documentation/getting-started-guide/language-setup/directory-default-language/#redirect-the-root-domain-to-the-default-language-directory
*/
if ( ! defined( 'ABSPATH' ) ){ die(); }

wp_redirect( home_url() );
exit;
?>

However, the redirection to the /hu/ URL is still not working.

What should I do next?

Best regards,
Mihály

wpml settings.jpg
wpml settings - page.jpg
May 29, 2023 at 8:33 am #13729755

Eran Helzer
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

I see you followed the documentation, which should have achieved your request. I can't know for certain why it didn't without further investigation.
In order to do that I will need access to your website, preferably a staging one where the issue is replicated.
Please make sure you backup your website before proceeding.
If it is a production website, I will be extra careful, and let me know if I do not have permission to change any settings.

Your next reply will be private so you can share sign in details.

Thanks

May 31, 2023 at 12:23 pm #13747521

Eran Helzer
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

I just visited your website and I believe I have an answer. First I tried going to the home page and as you said it does not redirect. Then after logging in I tried again and this time the redirect did work.
I checked and saw that you are using WP Rocket for caching.
I believe that you have a cached version of the page before you changed it to use the redirect template. The reason it works after logging in is that WP Rocket has a setting to use cache for logged in users which you left disabled. The reason the cache doesn't use the new version is that the cache time-to-live is unlimited.

To fix this you need to reload your cache so that it uses the update page.
hidden link
I added a short video for clarity.
hidden link?

Please update me if this resolves your issue.

Regards,
Eran

June 1, 2023 at 6:49 am #13751091

krisztianK

Dear Eran,

You have given me an idea... I have switched on the "Never cache this page" option of WP Rocket on WPML's Root redirect. I have cleared all the cache, and now it works as it should.

Thank you for your time and for helping me think through this again!

Best regards,
Mihály

wpml - Képkivágás.JPG
June 1, 2023 at 6:52 am #13751115

krisztianK

That's great to hear! I'm glad your issue has been resolved. Thank you and have a great day!