This thread is resolved. Here is a description of the problem and solution.
Problem:
The client is experiencing issues with regex redirects in Yoast SEO not functioning correctly when used with the WPML plugin. Specifically, redirects that include a language directory (e.g., /de/) fail, resulting in a 404 error.
Solution:
We recommend trying the following workaround:
1. Ensure you have a backup of your site.
2. Open the file
/wp-content/plugins/wp-seo-multilingual/classes/class-wpml-wpseo-redirection.php
in a code editor.
3. Replace the existing loop at line number 34 with the following code:
foreach ($redirections as $redirection) {<br />if($redirection['format'] == 'regex'){<br />if(strpos($url, '/', 0) !== 0){<br />$url = '/' . $url;<br />}<br />preg_match('~' . $redirection['origin'] . '~', $url, $matches);<br />if(count($matches) > 0){<br />return true;<br />}<br />} else if($redirection['origin'] === $url || '/' . $redirection['origin'] === $url){<br />return true;<br />}<br />}
4. Save the changes.
**** Important! Please make a full site backup (files and DB) before you proceed with these steps****
Additionally, we have published an errata page with two workarounds for this issue, which can be found here: https://wpml.org/errata/yoast-seo-redirection-regex-rules-differ-across-languages-with-wpml/
If this solution does not resolve your issue or seems irrelevant due to being outdated or not applicable to your case, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If further assistance is needed, please open a new support ticket at WPML support forum.
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.
Tagged: Bug
This topic contains 6 replies, has 2 voices.
Last updated by Itamar 1 year, 7 months ago.
Assisted by: Itamar.
Author | Posts |
---|---|
June 13, 2023 at 8:44 pm #13820155 | |
marcH-44 |
I am trying to: regex redirect in Yoast -Yoast tested and confirmed unwanted interaction with WPML Link to a page where the issue can be seen: daosoma.com/de/ab I expected to see: redirect to daosoma.com/de/transkulturelle-psychotherapie Instead, I got: 404 not found -- From: Yoast Support <support@yoast.com> Ramon replied Thanks for your continued patience. We can imagine how frustrating it can be when the redirects you've entered in Yoast SEO Premium don't work. Let's investigate this issue further and get to the bottom of this issue. First of all, we'd like to clarify that the forward slash / doesn't have to be escaped as it's not a special character. You can find the list of Regex special characters on this page. That said, we implemented the regex redirects you provided in your email from June 11 in our testing environment, tested them, and verified they worked as expected. Having a closer look at your website, we noticed you're running the WPML plugin. We then enabled WPML on our test site, and the regex redirects that included a language directory, i.e. /de/ stopped working. Thank you for bringing this issue to our attention. We've confirmed the problem you reported and have created a bug report for our development team. Workaround What's next? If you have any further information that may affect the prioritization or help our development team solve this bug, please feel invited to reply to this email. As soon as our development team has a clear indication in which release this problem will be solved, we'll send you an email to inform you. Additionally, we highly recommend reporting plugin conflicts to the developer of the conflicting plugin (WPML in this case) as they may have additional information vital to providing a resolution. Having both teams work on the issue is a benefit to you. How would you rate my reply? Thanks and regards, -- Marc Heusser replied TIA and best regards Marc Victoria replied Thank you for getting back to us. We are reviewing your reply and will get back to you as soon as possible. Thank you for your patience! Thanks and regards, -- Want to further optimize your website? Improve your SEO skills with our online SEO training courses! Have you seen our Help Center? This will probably have the answer you're looking for! an example is not a man page for Yoast redirect regexes. Where is the standard spec to be found? de/ab -> de/transkulturelle-psychotherapie does work, redirects hidden link to hidden link (literal match) So entering your example What could be wrong? Please get me more information on how these regex work, if there needs to be a specification ot a delimiter character like / first, etc Thank you in advance Marc Thanks for contacting the Yoast support team. We are sorry to hear that you're not finding enough information about Yoast SEO Premium redirects manager regex support. We can imagine how this could be disappointing for you. Let's sort this out right away! The redirects manager regex tab support the standard spec. This means you could capture groups and match strings. We even tested the backreference by following the example given here of ([a-c])x\1x\1 that should match axaxa, bxbxb and cxcxc and that worked as well. So, you should be able to use backreference in the regular expression based on your needs. Unfortunately, since these are very powerful we are unable to create them for you or offer advice as we do not want to put you or us in a position where we suggest something and it breaks your site. Let us know if there's anything else we can assist you with; we're happy to help. Thanks and regards, -- Want to further optimize your website? Improve your SEO skills with our online SEO training courses! Have you seen our Help Center? This will probably have the answer you're looking for! |
June 15, 2023 at 7:53 am #13830083 | |
Itamar Supporter
Languages: English (English ) Hebrew (עברית ) Timezone: Asia/Jerusalem (GMT+02:00) |
Hi, Marc. Currently, I cannot see this problem. When I try this URL: hidden link, I get redirected to hidden link. Is it because you manually inserted the redirection, not as a regex? In any case, if the problem persists, I suspect the following to cause the problem. In WPML -> Languages -> Language URL format, you have selected the option `Different languages in directories`. And then, you also selected the option `Use directory for default language`. It seems you also added a redirection from hidden link to hidden link. But you did not add any root page or HTML file as we instructed in our guide. Could you please add a root page or an HTML and check if it solves the problem? Thanks, |
June 18, 2023 at 3:42 am #13844513 | |
marcH-44 |
The issue persists, has no relation to the idea given by WPML, Yoast has confirmed the issue on their test bed. |
June 18, 2023 at 9:40 am #13844873 | |
Itamar Supporter
Languages: English (English ) Hebrew (עברית ) Timezone: Asia/Jerusalem (GMT+02:00) |
Hi, and thanks for trying my suggestions. I'm unfamiliar with Yoast regex redirections. Can you please help me replicate the issue on a test site, and then I'll escalate it to our second-tier supporters? For this, I created a test website with a clean WordPress install. You can access it through this link: hidden link With this link, you'll be directly logged in. I've already configured the test site to have German as the default language and English as the second language. Please add the regex to the Yoast plugin and replicate the issue. When everything is finished, and you can replicate the problem, please let us know. Thanks, |
June 18, 2023 at 10:22 am #13845153 | |
marcH-44 |
It would be best to talk to Yoast engineers as they have replicated it already as they suggested as it is proven to be an interaction between WPML and Yoast plug-in |
June 19, 2023 at 11:54 am #13851047 | |
Itamar Supporter
Languages: English (English ) Hebrew (עברית ) Timezone: Asia/Jerusalem (GMT+02:00) |
Hi, This issue has been escalated to our developers. We have a possible workaround. We cannot know if it will work in your case because we are missing information about it. If you wish, you can try it on your site and see if it works for you. Here is what you need to do. 1. Take a backup of your site in case something goes wrong. 2. Edit the following file with a code editor. /wp-content/plugins/wp-seo-multilingual/classes/class-wpml-wpseo-redirection.php 3. Replace the following loop in line number 34: foreach ( $redirections as $redirection ) { if ( $redirection['origin'] === $url || '/' . $redirection['origin'] === $url ) { return true; } } With this loop: foreach ( $redirections as $redirection ) { if($redirection['format'] == 'regex'){ // Ensure $url starts with /, if regex would need to check if string starts with this is needed. if(strpos($url, '/', 0) !== 0){ $url = '/' . $url; } // Lets use ~ as a regex delimiter instead of /, as we are matching a URL. preg_match('~' . $redirection['origin'] . '~', $url, $matches); if(count($matches) > 0){ return true; } } else if($redirection['origin'] === $url || '/' . $redirection['origin'] === $url){ return true; } } 4. Save the changes in the file. I have no ETA for when this fix will be included in future versions of WPML SEO. But I'll keep you updated here on any news regarding this issue. Cheers, |
June 20, 2023 at 4:41 pm #13862159 | |
Itamar Supporter
Languages: English (English ) Hebrew (עברית ) Timezone: Asia/Jerusalem (GMT+02:00) |
Hi, For your information, we've published an errata page that includes two workarounds for this case. https://wpml.org/errata/yoast-seo-redirection-regex-rules-differ-across-languages-with-wpml/ |