Skip Navigation

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.

Tagged: 

This topic contains 1 reply, has 0 voices.

Last updated by Dražen 1 week, 2 days ago.

Assisted by: Dražen.

Author Posts
January 23, 2025 at 8:06 am #16625880

danielI-23

Background of the issue:
I am trying to publish a post titled XYZ on site.com/news/xyz using a custom URL rewrite rule that adds /news/ to all my posts. When I upload a document named xyz.jpg to the media library, WordPress creates an attachment page at site.com/xyz. I don't mind these attachment pages, but when WPML is active, visiting site.com/news/xyz redirects me to site.com/xyz. I noticed a 301 request with a header 'X-Redirect-By: WPML' as seen here: hidden link.

Symptoms:
When WPML is active, visiting my post URL site.com/news/xyz redirects to the attachment page site.com/xyz. The issue is identified by a 301 redirect with 'X-Redirect-By: WPML'.

Questions:
Why is WPML redirecting my post URL to the attachment page URL?
How can I disable this redirect behavior?

January 23, 2025 at 12:14 pm #16627623

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hello,

thanks for contacting us.

I checked further, and you forgot to mention posts are set as Not translatable. This seems to be a known bug and it is escalated to our developers but I think it is a low priority, and it will take some time before we have a permanent fix.

What I can suggest is to try the following:

1) Possible workaround:
go to: wp-content/plugins/sitepress-multilingual-cms/classes/query-filtering/class-wpml-404-guess.php
adjust the method: \WPML_404_Guess::order_by_type_and_language_snippet
Change from:

			$order_by .= ' , ' . $this->order_by_post_type_snippet();

to:

$post_order = $this->order_by_post_type_snippet();
			$orderclone = $order_by;
			$order_by = $post_order . ' , ' . $orderclone;

Of course, this may break the translations in the end, please test it on the staging site.

2) Setting the post to be translatable.

3) Using different names / slugs for post and images, to avoid such issue.

Hope this helps.

Regards,
Drazen