Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client reported a redirect issue with image attachments when WPML is enabled, which was negatively impacting SEO. The issue was isolated to WPML after disabling all other plugins.
Solution:
We analyzed the situation and found that the redirects were due to the way WPML handles media translations. Each translated media item gets a new URL, and when the language prefix is not present in the URL, WordPress redirects to the correct URL. This behavior is expected and is managed by WordPress's default redirection mechanism. To address the client's concern about SEO and ensure proper URL handling, we recommended enabling the "Redirect Attachment URLs to Attachment Parent" feature in the All in One SEO plugin. This setting redirects attachment URLs to the parent post URL, which is the default WordPress behavior.

If this solution does not resolve your issue, or if it seems outdated or irrelevant 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 the problem persists, please open a new support ticket.

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 13 replies, has 2 voices.

Last updated by Bobby 9 months, 1 week ago.

Assisted by: Bobby.

Author Posts
July 9, 2024 at 11:05 pm #15923620

eliK-3

Background of the issue:
After an SEO audit and a lengthy investigation into issues flagged within Google Search Console, I have been advised that WPML is causing a strange redirect issue that involves image attachments. This seems to be negatively impacting SEO. A screen recording of my site in troubleshooting mode (all plugins disabled) shows the redirect problem resolved. Then when WPML is enabled, the redirect problem occurs. This would seem to isolate the problem to WPML.

Here is a the screen recording of the problem (conducted by AISEO plugin support):
hidden link

Symptoms:
Some URLs are redirecting to other URLs, which is negatively impacting SEO.

Questions:
How can I disable WPML redirects?
What steps can I take to resolve the redirect issue caused by WPML?

July 10, 2024 at 12:12 am #15923804

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi there,

Thank you for the screencast, I have watched it and understand the issue you are experiencing.

If possible, please share one of those URLs with me, I'd like to run them through a redirect check.

Also, go to Media and locate one of those media, review the URL shown in the backend does it match the URL you are getting redirected to?

July 10, 2024 at 2:16 am #15924342

eliK-3

Here is a non-exhaustive list of affected URLs. I will perform the backend procedure you recommended momentarily:
hidden link
hidden link hidden link
hidden link
hidden link
hidden link
hidden link
hidden link hidden link hidden link hidden link hidden link
hidden link
hidden link hidden link hidden link hidden link hidden link
hidden link hidden link hidden link hidden link hidden link hidden link hidden link hidden link hidden link hidden link hidden link hidden link
hidden link

July 10, 2024 at 2:42 am #15924475

eliK-3

I had a look at the WordPress backend for the URL featured in the screencast. This is the URL I found for the file:
hidden link

July 10, 2024 at 2:45 am #15924502

eliK-3

In answer to your query, the URL in the backend does not match the URL in the screencast. The URL in the screencast seems to have "-2" appended to it.

July 10, 2024 at 8:32 pm #15930186

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Let's use this URL as an example: hidden link

I can see what is happening.

Your website has 2 languages English and Japanese.

The default language is English and the image was uploaded first in English as expected with the URL /11056820_10103016418974093_473963436_n/.

The media has also been made available in Japanese which means that there is a separate DB entry and the URL for the Japanese media is /11056820_10103016418974093_473963436_n-2/ (notice the -2)

When WPML is activated the Japanese language exists therefore the correct URL for that media is:

hidden link (notice /ja/)

which is why when trying to access the URL with the -2 without the /ja/ in it it redirects to the URL with out it, that redirect is done by WordPress.

see here:

>>> <em><u>hidden link</u></em>

> --------------------------------------------
> 301 Moved Permanently
> --------------------------------------------

Status:	301 Moved Permanently
Code:	301
Date:	Wed, 10 Jul 2024 20:30:40 GMT
Server:	nginx/1.21.6
Content-Type:	text/html; charset=UTF-8
Content-Length:	0
cf-edge-cache:	cache,platform=wordpress
Expires:	Wed, 10 Jul 2024 21:30:40 GMT
Cache-Control:	max-age=3600
X-Redirect-By:	WordPress
Location:	<em><u>hidden link</u></em>
host-header:	c2hhcmVkLmJsdWVob3N0LmNvbQ==
X-Endurance-Cache-Level:	2
X-nginx-cache:	WordPress
X-Server-Cache:	true
X-Proxy-Cache:	MISS
Connection:	close

In summary that is expected because in the eyes of WordPress that URL is wrong so they quickly handled that by creating the redirect.

When WPML is deactivated /ja/ is no longer used thus the URL now technically exists as

hidden link

July 10, 2024 at 9:28 pm #15930294

eliK-3

I think I may understand what you are saying. But why, in the first place are there erroneous copies of the Japanese media pages (without /ja/) that are redirected only when WPML is active? Could WPML somehow be multiplying orphan media pages that WP needs to redirect?

If you look at the list of URLs I sent above, none contain /ja/. Here is an example:

hidden link

This page also has a Japanese version:
hidden link

According to your explanation, if I understand it, this is the original for both pages:
hidden link

However, there is also a Japanese version of this page:
hidden link

If your explanation is correct, then WPML is creating at least two versions for every English original media, one with /ja/ and one without. When WPML is active, the redirect is to the original file without -2/. When WPML is off, there is no redirect.

July 10, 2024 at 9:30 pm #15930295

eliK-3

Once we understand what is going on here, do you know how I can resolve it?

July 10, 2024 at 11:11 pm #15930474

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

To summarize what is happening.

Your media URL is:

hidden link

This media is translated into Japanese, the Japanese URL is:

hidden link

Therefore based on this, the URL below is wrong:
hidden link

WordPress by default will redirect to a URL that makes sense, since removing -2 redirects to the correct URL WP does that which you can see in the redirect log in my previous

It works when deactivating WPML because the directory /ja/ is no longer used so now the URL is correct.

hidden link

I hope that is more clear now.

When a media is translated a new database entry is created which is why when you deactivate WPML there are 2 entries shown in Media for the same media, this is expected.

--------------------------------------------------------

The question is why is your software picking up this URL when WPML is activated since this is not a correct URL:
hidden link

is this being used somewhere as a hardlink?

July 11, 2024 at 1:14 am #15930773

eliK-3

I don't know. How do I go about checking?

I'm not sure where to go from here.

July 11, 2024 at 5:42 pm #15936936

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Looking at your sitemap I can confirm that the wrong URLs are there, which will trigger 301 redirects.

hidden link

WPML uses always the same image for both languages, so the URL path is always going to be the same unless you upload a different image (title) for 2nd language and use it like that.

Did you ever go to WPML->Media Translation and upload an image?

How is that media page exactly created?

I would like to request temporary access (wp-admin and FTP) to your site to test the issue.
(preferably to a test site where the problem has been replicated if possible)

**Before we proceed It is necessary to take FULL BACKUP of your database and your website. Providing us with access, you agree that a backup has been taken **

I often use the Duplicator plugin for this purpose: http://wordpress.org/plugins/duplicator/
You will find the needed fields for this below the comment area when you log in to leave your next reply.
The information you enter is private which means only you and I have access to it.

NOTE: If access to the live site is not possible and the staging site does not exist please provide me with a duplicator package created with the duplicator plugin.

Thank you,
Bobby

July 12, 2024 at 6:40 pm #15943988

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi there,

It looks like this is caused by the SEO plugin All in One SEO configuration. Media was set to be included in the sitemap and also to have a URL pointing back to a media page.

I have disabled this from being indexed by changing the 2 options below.

There is still, however, one weird situation which is the following:

1. Go to Media -> Library
2. Click on a media -> at the bottom click on Edit more details
3. The media page will open -> notice the permalink it's similar to a page permalink.

that is not expected, but it is beyond our support and possibly caused by the theme or a third party plugin.

EDIT: I checked again and it looks like the changes I made in the SEO plugin resolve this issue and now the URL opens the attachment file. like this one for example which is expected behavior.

hidden link

Now I no longer see these pages in the sitemap.
hidden link

If I go to Media -> Library and then view an image -> click on If you're using All in One SEO (AIOSEO) and want to remove media pages from your XML Sitemap, you can uncheck the Media / Attachments box in the Post Types setting:
Go to Sitemaps in the AIOSEO menu
Scroll down to the Advanced Settings section
Click the toggle to display the Advanced Settings
Uncheck the Media / Attachments box in the Post Types setting

Disable image attachment pages
Go to All in One SEO > Search Appearance, click the Image SEO tab, and set Redirect Attachment URLs to Attachment.

To redirect an image attachment to a post, set Redirect Attachment URLs to Attachment Parent.

To hide attachment pages from search results, set the setting to Disabled.

I believe with me doing the above configuration settings you should be OK now in terms of SEO. I recommend re run your audit but these URLs are no longer listed in your sitemap.

July 14, 2024 at 10:17 pm #15950885

eliK-3

Thank you for your help. I was not able to find the "Edit more details." Section you mentioned so I could not confirm the strange behaviour.

I have decided to leave the Exclude Images section as set to "no." I do not want images excluded from the site map. I think having the images available for indexing may be good for SEO in the long run.

Instead, I have set attachment URLs to be redirected to the parent post. I think this is appropriate for my site.

I have forwarded everything you told me up until July 10th to AIOSEO support but have not received a response. I still do not understand the cause of the original problem.

I will check Google Search Console soon to see if the core problems have been resolved and will request another SEO audit in the near future.

July 15, 2024 at 5:19 pm #15955906

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Thank you for updating me!

The cause of the original problem is not related to WPML rather it has to do with enabling this feature "Redirect Attachment URLs to Attachment Parent." This will redirect images to an actual post.

You want to enable this "Redirect Attachment URLs to Attachment.", which is the default behavior of WordPress.

Go to All in One SEO > Search Appearance, click the Image SEO tab and set Redirect Attachment URLs to Attachment.