Resolved
Resolved in: 3.7.0
Overview of the issue
Since WPML 3.6.3 some users are experiencing incorrect browser redirections when the Language URL format is configured on WPML -> Languages page with the following settings:
- Different languages in directories
- Use directory for default language => enabled
Workaround
This problem will be addressed in the next WPML version.
In the meantime we have a patch you can apply to the class-wpml-canonicals-hooks.php file, found in the ../wp-content/plugins/sitepress-multilingual-cms/classes/canonicals/ folder.
Replace the following whole block of code, around line 34.:
public function redirect_pages_from_root_to_default_lang_dir() { if ( is_page() ) { $current_path = wpml_parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); $canonical_url = get_permalink( get_queried_object_id() ); $canonical_path = wpml_parse_url( $canonical_url, PHP_URL_PATH ); $canonical_path = $this->get_paginated_canonical_path( $canonical_path ); if ( $current_path !== $canonical_path ) { $current_query = wpml_parse_url( $_SERVER['REQUEST_URI'], PHP_URL_QUERY ); parse_str( $current_query, $current_query_array ); $canonical_url = add_query_arg( $current_query_array, $canonical_url ); $this->sitepress->get_wp_api()->wp_safe_redirect( $canonical_url, 301 ); } } }
With:
public function redirect_pages_from_root_to_default_lang_dir() { global $wpml_url_converter; if ( is_page() && ! WPML_Root_Page::is_current_request_root() ) { $lang = $this->sitepress->get_current_language(); $current_uri = $_SERVER['REQUEST_URI']; $abs_home = $wpml_url_converter->get_abs_home(); $install_subdir = wpml_parse_url( $abs_home, PHP_URL_PATH ); $actual_uri = preg_replace( '#^' . $install_subdir . '#', '', $current_uri ); $actual_uri = '/' . ltrim( $actual_uri, '/' ); if ( 0 !== strpos( $actual_uri, '/' . $lang . '/' ) ) { $canonical_uri = trailingslashit( $install_subdir ) . $lang . $actual_uri; $canonical_uri = user_trailingslashit( $canonical_uri ); $this->sitepress->get_wp_api()->wp_safe_redirect( $canonical_uri, 301 ); } } }
Hello to all,
Thanks for the patch. The problem is solved if the site is located on the root, but if it’s located in a directory causes 404 errors.
Example: http://www.webserver.com/en/website/en/
Thanks anyway
Hello @massimoM-6,
Thanks for your comment. We are currently investigating this issue for edge cases and we’ll update the errata as soon as possible.
Regards,
Pierre
Hi, this patch fixed the exact problem that I was having. I was searching for hours and luckily came across this.
What I really came here to leave a message about was a more effective way of informing users about patches and bugs, and to clean up old info. The WPML forum contains a wealth of info about bugs and how they were fixed/patched, but over time, information about the problems or the fixes themselves become outdated. My suggestion is for these old posts to be closed, and a link to the latest information or errata to be provided. This would save hours or searching and using outdated information.
For example, in my particular case, I tried several things with translating the WC endpoints vs leaving them untranslated etc, but if I had seen this latest post first, I would not have had to gone through those troubleshooting steps.
I’m not sure if there’s a newsletter of some sort, but if there’s some way to “push” fix notifications to users (paying customers with valid support license), that would be much appreciated.
Hello, i also had this problem using last version of WooCommerce, all Woocommerce endpoints were broken, meaning no acccess to users accounts and paiement.
The above fix seemed to fix it.
There should be a way to be warned with this kind of problems, because i spent hours looking for a solution ! But thanks for the fix!
Hello Fortune Rice and fabriceV-2,
Currently, we have a “‘Known issues and their solutions” section at the bottom of each support page with a link to the errata main page. On this page, we have a parametric search to find the right issue.
The errata should be updated and marked as resolved when a fix is released in a new version.
Generally speaking, the support team is responsible for pointing the users to the right errata.
I will pass your suggestions to our team to see what can be done to improve it.
Thanks,
Pierre
Hi, I had this issue with WooCommerce. It would redirect users to an empty cart after checkout (with the message: Checkout is not available whilst your cart is empty). This patch fixed the issue, thanks.
Lucky I found this one, the wpml forums are a jungle 🙂
Hi.
This workaround works but not completely.
When you want to see “view” a page from the Dashboard, it does not work.
I want to see a French page, but it shows me the English version (the default language of my web site: http://www.trekpyrenees.com)
Miguel
Hi @miguelI,
In order to further investigate your issue, could you please open a ticket on the Support Forum with your debug information?
Also, could you make sure the redirection cache is disabled in your browser (see this post => https://salferrarello.com/chrome-clear-redirect-cache/).
Thanks,
Pierre
Thanks Pierre for your answer.
Regarding the redirection cache, I do not use Google Chrome. I use Firefox. So this article is not useful.
I’m going to open a ticket.
Thanks
Hello
The my account page no longer works for me. Reading through several threads here, I did the following:
– I tried the above, though without results.
– I tried installing the latest beta, without results.
kursiv-software.com/mein-konto should lead to my account, but now even creates a server error.
I’m stuck – any suggestions appreciated.
Karsten
Hello @Karsten,
It’s hard to say what’s wrong with your setup. To have a deeper investigation, could you please open a ticket on the support forum with your debug information? A supporter will provide a dedicated assistance to you.
Thanks,
Pierre
Thank you, Pierre!
I just followed your suggestion.
Regards
Karsten
Damn. Just spend 3 hours on this issue. Thanks for the fix.
Me too, 3 hours. >_<"
Thanks for fix! patch works for me!
Add to a new release please as soon as possibe.
OMG, thanks – not three hours of my life, just about one 🙂 I found my own hack in the meantime, completely removing redirect_pages_from_root_to_default_lang_dir action from template_redirect hook — i suppose it should not break anything in URLs resolving — if I am not using Browser language redirect, right? –Jan
Hi @janK-34,
Yes, removing the whole action will not break other features.
Thanks,
Pierre
Yeah same error here, could not reach the woocommerce endpoints like
“/en/my-account/orders” always get redirected to “/en/my-account”.
Have found myself the function “redirect_pages_from_root_to_default_lang_dir” was creating the redirect and so found this thread.
Fixed it temporarily by commented out line 26 in “class-wpml-canonicals-hooks.php”
//add_action( 'template_redirect', array( $this, 'redirect_pages_from_root_to_default_lang_dir' ) );
Hi team,
greats fix.
I’m searching the solution since few days after a customer say me that’s a problem with account page.
The fix is ok for me.
Many thanks
Nicolas
Thanks!
This code solved my problem!
This fix should happen automatically once the code has been replaced, correct? I’ve replaced mine, but my Farsi content is still being redirected to English.
Hello Derek,
Yes, after applying the patch you should not be redirected anymore. But you need to make sure your browser is not caching the redirection (see this post for Chrome => https://salferrarello.com/chrome-clear-redirect-cache/).
If you still have an issue, could you please open a ticket on the support forum? You will get a custom assistance.
Thanks,
Pierre
I did the patch job via FTP but it didn’t work at all.
Now I cannot even login to WordPress and get the following error message:
Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /homepages/23/d504965203/htdocs/new.allimonecolodge.com/wp-content/plugins/sitepress-multilingual-cms/inc/request-handling/redirection/wpml-rootpage-redirect-by-subdir.class.php on line 47
Warning: include(http://www.allimonecolodge.com/new.allimonecolodge.com/wp-content/languages/): failed to open stream: no suitable wrapper could be found in /homepages/23/d504965203/htdocs/new.allimonecolodge.com/wp-content/plugins/sitepress-multilingual-cms/inc/request-handling/redirection/wpml-rootpage-redirect-by-subdir.class.php on line 47
Warning: include(): Failed opening ‘http://www.allimonecolodge.com/new.allimonecolodge.com/wp-content/languages/’ for inclusion (include_path=’.:/usr/lib/php7.0′) in /homepages/23/d504965203/htdocs/new.allimonecolodge.com/wp-content/plugins/sitepress-multilingual-cms/inc/request-handling/redirection/wpml-rootpage-redirect-by-subdir.class.php on line 47
Please help!
Hello Juliette Kando,
As far as I can see, you have this warning only on the root page, probably because you have set a non-existing “HTML page” in WPML -> Language URL Format. I think this warning is occurring only on the root page and your backend is still accessible.
Can you try to access the admin page WPML -> Language URL format and check that you have a valid HTML file in the input? Otherwise, you can also select the option “A page” and create a root page inside WordPress.
If the issue persist, I invite you to open a ticket on the support forum to get a more dedicated assistance.
Thanks,
Pierre
Hi pierre,
Thank you Pierre for your prompt reply.
No, the error message occurred on all the pages. even when I tried to login to my WP dashboard. By chance, via “history” I managed to get into the site via allimonecolodge.com/en. The problem is that all our publicity is on allimonecolodge.com so I’ve had to disable WPML until this issue is resolved. I’ve been struggling with this for over 2 days now and am at my wits end.
Is there anyone who can install WPML on our website so it works for English and Spanish with the English version remaining allimonecolodge.com (witout the /en extension) and the Spanish version allimonecolodge/es?
Your help would be much appreciated,
Juliette
Juliette, please open a ticket on the support forum, you will get a dedicated assistance 🙂
Thanks,
Pierre
One problem with that solution is that when using beaverbuilder a trailing slash is added to the path:
e.g. http://yourdomain.com/de/b2b/?fl_builder gets to http://yourdomain.com/de/b2b/?fl_builder/
it works after manual removing the slash this but i’m sure this behaviour will also cause other problems.
Any ideas?
Hello @sebastianG-25,
Thank you for your feedback. This needs to be investigated on the support. So could you please open a support ticket with your debug information? We need this information about your setup to try and reproduce the issue.
Thanks,
Pierre
Done – looking forward to the solution – this is keeping me from finishing my wordpress updates.