This thread is resolved. Here is a description of the problem and solution.
Problem:
When WPML is active, visiting the custom URL site.com/news/xyz redirects to the attachment page site.com/xyz due to a conflict between post URLs and attachment URLs, identified by a 301 redirect tagged 'X-Redirect-By: WPML'.
Solution:
1) Modify the code in
wp-content/plugins/sitepress-multilingual-cms/classes/query-filtering/class-wpml-404-guess.php
. Change the method
\WPML_404_Guess::order_by_type_and_language_snippet
from:
$order_by .= ' , ' . $this->order_by_post_type_snippet();
to:
$post_order = $this->order_by_post_type_snippet();<br />$orderclone = $order_by;<br />$order_by = $post_order . ' , ' . $orderclone;
Please test this on a staging site as it may affect translations.
2) Set the post to be translatable to avoid conflicts.
3) Use different names/slugs for posts and images to prevent similar issues.
If this solution does not resolve your issue or seems outdated, we 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.