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.

Our wait time is higher than usual, please make sure you are meeting the minimum requirement - https://wpml.org/home/minimum-requirements before you report issues, and if you can take a look at current Known Issues - https://wpml.org/known-issues/. Thank you.
Sun Mon Tue Wed Thu Fri Sat
9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 - -
- - - - - - -

Supporter timezone: Asia/Yerevan (GMT+04:00)

Tagged: 

This topic contains 0 replies, has 0 voices.

Last updated by Christopher Amirian 1 week, 3 days ago.

Assisted by: Christopher Amirian.

Author Posts
March 10, 2025 at 7:30 am #16794561

Chris Jean

Background of the issue:
I am trying to access a REST API endpoint using the non-permalink form of the link as described in the WP developer docs (https://developer.wordpress.org/rest-api/extending-the-rest-api/routes-and-endpoints/#routes-vs-endpoints): "On sites without pretty permalinks, the route is instead added to the URL as the rest_route parameter. For the above example, the full URL would then be hidden link;. On this site, I have followed the instructions to set up WPML to use Different Languages in Directories (https://wpml.org/documentation/getting-started-guide/language-setup/language-url-options/#different-languages-in-directories) and "Use directory for default language" (https://wpml.org/documentation/getting-started-guide/language-setup/directory-default-language/). I should note that simply using the pretty permalink version of the URL is not an option. I was able to fix the issue by modifying line 556 of `sitepress.class.php` in version 4.7.1 to the following: if ( ! defined( 'WP_ADMIN' ) && isset( $_SERVER['HTTP_HOST'] ) && ! empty( $_SERVER['HTTP_HOST'] ) && $_SERVER['HTTP_HOST'] && ! defined( 'WP_CLI' ) && did_action( 'init' ) && ! $isLoadingATEAutomaticTranslationWidget && empty( $_GET['rest_route'] ) { Note the addition of the rest_route check at the end. I'm not sure that this the best solution however. Perhaps a bit more sophisticated version of this would work.

Symptoms:
The URL is redirected to a broken version (hidden link) which WP no longer recognizes as a REST API request and outputs: {"code":"rest_no_route","message":"No route was found matching the URL and request method.","data":{"status":404}}.

Questions:
How can I fix the broken redirects for REST API requests using the rest_route query parameter?
Is there a more sophisticated solution than modifying line 556 of sitepress.class.php?

March 10, 2025 at 7:57 am #16794668

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

I shared the information with the second tier support. If there are questions that needs to be answered I will be in contact with you,

Thank you.

March 11, 2025 at 6:11 am #16799407

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi,

There are a few points that our second-tier support mentioned.

1) A URL like this even does not work when WPML is not active:

hidden link

Is it possible to clarify why wp-json is added there as it causes the URL to fail even without WPML.

2) On the site neoncat.party there is an immediate 302 redirection.

Would you please setup a Root page following the steps mentioned in the documentation below?

https://wpml.org/documentation/getting-started-guide/language-setup/directory-default-language/#what-is-a-root-page-and-do-i-need-one

If the issue persists we still need your help implementing whatever you do on a clean installation to be able to see the result to be able to troubleshoot:

hidden link

By the way we are aware of your code suggestion and we thank you for that. Before considering touching the core code we need to have a clear replication on a clean installation to rule out any exceptions.

Thanks.

March 13, 2025 at 4:54 pm #16813002

Chris Jean

Hi Christopher. When posting this issue, I hoped to keep things a bit simple as the central issue was WPML attempting a redirect when it shouldn't be. I'll be more specific.

The TL;DR issue is attempting calls using the rest_route URL query parameter and not the REST API pretty permalink URL causes WPML to do a 302 redirect when following documented setup guides for using language directories (and possibly other configs). This redirect is a bug in WPML which breaks many of these calls, particularly authenticated calls and non-GET method calls (such as PUT, POST, and DELETE) as the 302 redirect causes the request body to be lost, resulting in the loss of all non-URL-parameter data.

Since posting technical details here isn't reliable, I created a Github gist with the key details that a developer can use to better see the issue. hidden link

"1) A URL like this even does not work when WPML is not active:"

Sorry, I got the URL wrong. It should be:

hidden link

The URL doesn't matter so much though. I was only using it as an example that WPML is doing a redirect for a request to the REST API when it should leave the request alone. This is made clear in the gist I linked to above.

"2) On the site neoncat.party there is an immediate 302 redirection."

That immediate 302 redirect is due to following the "Redirecting the Root Domain to the Default Language Directory" instructions detailed here: https://wpml.org/documentation/getting-started-guide/language-setup/directory-default-language/#redirect-the-root-domain-to-the-default-language-directory

I did this because it matches the config of the original customer that reported this issue to us. However, I discovered that this does not affect this report since removing this modification does not change the behavior of the WPML redirect for REST API requests.

"Would you please setup a Root page following the steps mentioned in the documentation below?"

The site already had that change. You can see the settings for the test site in the attached image.

"If the issue persists we still need your help implementing whatever you do on a clean installation to be able to see the result to be able to troubleshoot:"

The issue will persist because it is a bug in the logic of your code. I gave the key configuration details in my original request and included the debug output from the plugin. I don't know what more I can provide, so I created an admin user on the site that you can test. You can find the login details here:

hidden link

I should note that asking us to change the WPML config to fix this issue is not an acceptable solution. I'm contacting you on behalf of a mutual customer who reported an issue to my company. I dug into the issue and found this bug. Fixing this specific bug in WPML resolved the issue our mutual customer reported to us. This customer told us that they are not willing to change any WPML configs to fix the issue.

Screenshot from 2025-03-13 10-19-58.png
March 15, 2025 at 6:03 pm #16820430

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi,

Thank you for the explanation. I asked the second tier support to give feedback.

We will ask additional questions if more clarification is needed.

March 17, 2025 at 1:58 pm #16825498

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi,

Thank you for the information, the issue is escalated by the second-tier support to developers.

Thanks.

March 24, 2025 at 4:30 pm #16853300

Chris Jean

Hi Christopher. Are there any updates on this issue?

March 25, 2025 at 1:19 pm #16857895

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+03:00)

Christopher is currently unavailable. I have confirmed that the issue is on our development team's list, but there are no updates at this time. We will keep you informed here as soon as there is more information.