Skip Navigation

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 33 replies, has 3 voices.

Last updated by Sumit 4 years, 5 months ago.

Assigned support staff: Sumit.

Author Posts
April 15, 2016 at 2:31 am #861714

scottT-2

I am trying to:

Go to the home page in French (non-default).

My site runs on separate domains per language. English is the default and is at ceso.test. French is also available, at saco.test.

URL of (my) website where problem appears:

(Not yet public.)

I expected to see:

I want to go to the home page in French: hidden link. I want that to show me the French home page.

Instead, I got:

I am redirected via a "Location" header to hidden link, the English version.

Other pages work just fine and I can switch between the two languages with no issues at all. It is only the home page (which is at the root path) which causes the issue.

The French translation of the home page definitely exists. When editing it, I can see that it knows it is a translation of the English version from the Languages box. The English version's edit page offers the link to edit the existing French version. Both are at permalink / (their bare domains).

Steps to duplicate the issue:

This happens every time. It does not depend on Accept-Language headers (that feature is disabled anyway).

This issue https://wpml.org/forums/topic/always-redirection-to-homepage-default-language/ looks like the same thing, but I cannot understand the Italian solution given there.

April 15, 2016 at 5:58 am #861762

scottT-2

I translated that other post, but the instructions did not help me.

April 15, 2016 at 6:15 am #861770

scottT-2

If I change the home page (on settings -> reading, change "front page displays", which is set to "static page", to another page), I can then see the proper home page in both languages and switch back and forth, but the new page I've designated as the home page now only ever shows up in English. It doesn't matter which language I was set to when I change this setting.

April 15, 2016 at 6:44 am #861787

scottT-2

I'm stepping through code to see where this redirection happens. I've found so far that it comes from redirect_canonical. But it's *already* at the canonical URL for the French home page, as far as I'm concerned. Digging deeper.

April 15, 2016 at 7:27 am #861827

scottT-2

redirect_canonical is supposed to be disabled by WPML_Root_Page_Actions@wpml_home_url_setup_root_page.

That method is supposed to be called in some cases by WPML_Rootpage_Redirect_By_Subdir@maybe_setup_rootpage, which in turn is sometimes supposed to be called by WPML_Rootpage_Redirect_By_Subdir@get_redirect_target. The only place which calls this is WPML_Frontend_Redirection@maybe_redirect.

But in WPML_Frontend_Redirection@maybe_redirect, the get_redirect_target method of $this->redirect_helper is called, but in my case $this->redirect_helper is a WPML_Redirect_By_Domain object, not a WPML_Rootpage_Redirect_By_Subdir object.

In other words, the redirect_canonical call is never disabled, and so happens during template_redirect.

Perhaps that's by design. Perhaps redirect_canonical is *supposed* to run in my case, and the URL we're at, "hidden link", is supposed to be found to be correct. But in redirect_canonical, by line 504 of canonical.php $redirect_url is "hidden link". I dug further and that value is chosen for $redirect_url on line 176 of the same file: the condition

is_page() && !is_feed() && 'page' == get_options('show_on_front') && get_queried_object_id() == get_option('page_on_front') && !$redirect_url

evaluates to true and so it is set to

home_url('/')

.

I think this is as far as I can go. Please tell me what's going wrong and how I can fix it.

April 15, 2016 at 8:06 am #861856

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Europe/Paris (GMT+02:00)

Hello Scott,

Welcome to WPML support forum.

That's impressive, I see that you have really explore what is going on. However I would like to ask you for a couple of things to cover all the basics and then dig into this situation :

1. Can you go to WPML -> Languages -> Browser language redirect and select the Disable browser language redirect option.

It could be another manifestation of this know issue:
https://wpml.org/errata/static-home-page-issue-language-parameter-browser-redirect/

2. Please check if this issue appears when:
- All non WPML Plugins are disabled. It will tell us if there is an interaction issue with other plugin.
- Theme is set to a WordPress default like Twenty Fourteen. Its will tell us if there is an interaction issue with your theme.
- If the problem disappears, start activating one at the time to track where the incompatibility is produced.

Best regards,
Andrés

April 15, 2016 at 9:58 am #862006

scottT-2

Hi, Andrés.

1. As stated in my original post (albeit not very clearly), that option is already disabled.

2. a) I tried disabling all non-WPML plugins; issue remains:

curl -I <em><u>hidden link</u></em>                                                                      
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Fri, 15 Apr 2016 09:54:21 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Set-Cookie: _icl_current_language=fr; expires=Sat, 16-Apr-2016 09:54:21 GMT; Max-Age=86400; path=/
Set-Cookie: _icl_current_language=fr; expires=Sat, 16-Apr-2016 09:54:21 GMT; Max-Age=86400; path=/
Location: <em><u>hidden link</u></em>
X-UA-Compatible: IE=Edge
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block

Note here that it's trying to set a cookie saying my current language is "fr" when I try to get hidden link (French), so it knows this at some level, yet is still redirecting me to hidden link (English). If I try to grab the English in the same way, it's trying to set the cookie to "en".

b) With the plugins still disabled, I set the theme to Twenty Fourteen. Same issue:

curl -I <em><u>hidden link</u></em>
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Fri, 15 Apr 2016 09:56:51 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Set-Cookie: _icl_current_language=fr; expires=Sat, 16-Apr-2016 09:56:51 GMT; Max-Age=86400; path=/
Set-Cookie: _icl_current_language=fr; expires=Sat, 16-Apr-2016 09:56:51 GMT; Max-Age=86400; path=/
Location: <em><u>hidden link</u></em>
X-UA-Compatible: IE=Edge
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block

c) Problem remains, so I can't follow the next instruction.

April 15, 2016 at 11:14 am #862075

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Europe/Paris (GMT+02:00)

I would like to request temporary access (wp-admin and FTP) to your test site to take a better look at the issue. Could you please indicate me how to replicate this behaviour?

You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

Maybe I'll need to replicate your site locally. For this, I’ll need to temporarily install a plugin called “Duplicator” on your site. This will allow me to create a copy of your site and your content. Once the problem is resolved I will delete the local site. Let me know if this is ok for you.

*Important: Be sure to backup your site and database first before you proceed!
You can use a plugin for this if you like. You can use the Duplicator plugin for this purpose.
See: http://wordpress.org/plugins/duplicator/

Privacy and Security when Providing Debug Information for Support:
https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

April 15, 2016 at 6:37 pm #862424

scottT-2

I've spun up a fresh temporary AWS for you to go wild in. Do whatever you like there. PMing you details.

April 15, 2016 at 6:38 pm #862425

scottT-2

...How do I PM you details?

April 18, 2016 at 6:04 am #862983

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Europe/Paris (GMT+02:00)

Hello Scott,

You should have seen a form at the bottom of the page. Is the case now?

Regards

April 18, 2016 at 7:15 am #863026

scottT-2

I just sent the information. The form was not visible until then -- I guess you forgot to activate it.

As I said, this is a temporary server, so go nuts. Since I've switched the theme to twenty fourteen, there's no language switcher visible. To see the issue, try to go to the "tmp-fr" version of the domain, and you'll see you're redirected to the "tmp-en" version. You'll find that there's no problem switching between the two on other pages.

April 18, 2016 at 9:34 am #863175

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Europe/Paris (GMT+02:00)

After checking your site, I can see that this redirection is even present when WPML is deactivated. I look for the possible places where it could be set but I couldn't find it.

As you can see, this problem is not related to WPML itself but your domains configuration. I recommend you to kindly verify that there is not any redirection from your CPanel or other any configuration panel from your hosting service.

Thank you for your understanding.

Regards,
Andrés

April 19, 2016 at 8:46 am #864100

scottT-2

Okay, thanks for finding that. But I'm not entirely convinced it's not a WPML thing.

Sure, the redirection happens without WPML, but that's expected. With only one language, of course the canonical URL of the main page is at the main configured domain for WordPress. There would only be one valid domain if I weren't using WPML and per-domain languages.

It's nothing to do with the server. We know this because as I discovered earlier, the redirection is coming from redirect_canonical and home_url. In other words, it's introduced at the PHP level, not the server level.

Can you replicate this on other domain-per-language sites, or do you not see the issue at all on those?

Can you maybe ask someone else to take a look?

In the mean time, I have added a nasty workaround.

I'm adding a filter to 'home_url'. It replaces the host in the $url passed to it (which is always the English one and I don't know why) with whatever is in the Host header, as long as the path is '/':

add_filter('home_url', 'homeUrlFilter', 10, 4);
function homeUrlFilter($url, $path, $orig_scheme, $blog_id)
{
    // FIXME: I couldn't solve an issue where the main page always redirects
    // to the English version, so this is a nasty workaround.
    if ($path === '/') {
        return http_build_url($url, ['host' => $_SERVER['HTTP_HOST']]);
    }
    return $url;
}

This workaround is not installed on the testing version I gave you access to.

April 19, 2016 at 10:05 am #864204

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Europe/Paris (GMT+02:00)

Thanks again for all this information, Scott.

When using different domains per language with WPML, the first thing we need to do is to have all the domains pointing to the same URL without any redirection. That's why I have deactivate WPML and check both of your domains.

As it varies from server to server, I recommend you to kindly read the following article about how to set up your domains in order to get them working correctly.
https://wpml.org/faq/server-setting-for-languages-in-different-domains/

Once it is done, the way to verify that they've been correctly set is deactivating WPML : you should be able to see in both domains the same WordPress content.

Does it help you to continue ?

Regards,
Andrés

The topic ‘[Closed] On home page (only), always redirected from French to English’ is closed to new replies.