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.

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

Problem:
Whenever someone types in a URL from a german post – without the language parameter – the site redirects to the english version of the post, instead of the german version with the language parameter.

Solution:
This is the default behaviour of the WPML when missing the language parameter. While the option for language parameter is set to Language name added as a parameter, adding the ?lang=de at the end of the link is necessary.

As a workaround you can add this code to the .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{QUERY_STRING} lang=de
# exclude all requests starting with /wp-admin/
RewriteCond %{REQUEST_URI} !^/wp-admin/.*$
RewriteRule ^(.*) /de/$1? [L,R=301]
</IfModule>

This topic contains 8 replies, has 2 voices.

Last updated by Radu 2 months, 1 week ago.

Assigned support staff: Radu.

Author Posts
August 3, 2019 at 7:26 am #4334163

andreasF-5

Hi,

I am using the option "language name added as a parameter" to separate the different languages on my site.

English is the main language, having no parameter. German is the secondary language with the parameter "?lang=de" added to the URL.

Whenever someone types in a URL from a german post – without the language parameter – the site redirects to the english version of the post, instead of the german version with the language parameter.

Example:
hidden link

redirects to:
hidden link

instead of:
hidden link

How can I fix this?

Kind Regards,
Andreas

August 4, 2019 at 9:58 pm #4336979

Radu
Supporter

Languages: English (English )

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

Hey Andreas,

I looked a bit into this and it seems that this is the default behaviour of the WPML when missing the language parameter. While the option for language parameter is set to Language name added as a parameter, adding the ?lang=de at the end of the link is necessary.

This is not a common request regarding the behaviour of the language redirect when the language parameter is not added to the URL. If you consider that this should be working as you described, you can submit a feature request here https://wpml.org/suggest-a-new-feature-for-wpml/ with the explanation of why you think that this should be changed. My colleagues are going over all the requests and see if they would be a great addition/change for our products.

Thanks,
Radu

August 5, 2019 at 5:02 pm #4342157

andreasF-5

Hi Radu,

I sent in a feature request but I didn't even get a link or some confirmation that my request got through.

Also, I have to say that this seems to me like a rather odd behaviour. Why would the redirect by default go to the post in the wrong language? It seems rather like a bug to me.

Kind Regards,
Andreas

August 7, 2019 at 8:46 am #4352931

Radu
Supporter

Languages: English (English )

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

Hey Andreas,

The language parameter is very important in any URL, whether it's added as parameter (?lang=de) or folder as folder (/de/). Leaving the link without the language parameter can cause issue in different situations and that's why accessing it without this part is not working. If you send a feature request, my colleagues will have a look at it and see if this is a good improvement for our plugin and if there's anything that can be done about it.

Regards,
Radu

August 7, 2019 at 11:45 am #4354505

andreasF-5

Dear Radu,

I have the feeling that you don't understand my request. I'm not talking about removing the language parameter. Could you please read my initial post again?

I'm talking about redirecting the user to the secondary language URL (with the language parameter!), in case the user types in the URL of the secondary language WITHOUT the language parameter. Currently this redirects to the primary language, which makes no sense whatsoever.

Example:
hidden link

redirects to:
hidden link

instead of:
hidden link

Do you understand me now?

Kind Regards,
Andreas

August 7, 2019 at 1:55 pm #4355731

Radu
Supporter

Languages: English (English )

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

Hey Andreas,

I understand what you asked for from the first message. However, when the language parameter is missing from the link (whether it's added as parameter, as directory, or as sub-domain), the post, page, or any other post type is made to fall back to the original language. This is the way that the plugin is made to work and this is the reason why I asked you to send a feature quest. This way, my colleagues can check this out and see if this is a good idea from both usability side but from the functionality side too.

For example, a post can have the same title on two different languages. In this case, accessing a link without the language parameter (?lang=de) will be an issue since WPML won't be able to know which language of that post should be displayed. I'm sure that there are other cases when missing the language parameter can create an issue but this is the only example that came through my mind at this point.

For now, as a workaround, you can try to use a redirect plugin like this one https://wordpress.org/plugins/redirection/. This way, you can create a redirect rule for each page.

Thanks,
Radu

August 7, 2019 at 8:50 pm #4358207

andreasF-5

Hi Radu,

thanks for your suggestion with the redirect plugin but it sounds rather tedious to manually redirect all posts and pages.

In response to your example: If a post has the same name in different languages, there is no redirect necessary when someone types in the URL without a language parameter. You will just see the version of the post without a language parameter (usually english). So, I don't see the issue here? I'm trying but I still can't come up with a case where it might cause problems to redirect to the URL that makes sense instead of falling back to the wrong language.

Kind Regards,
Andreas

August 7, 2019 at 9:40 pm #4358411

andreasF-5

Hi Radu,

so I switched to language in directories and redirected all old links with this code in my .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{QUERY_STRING} lang=de
# exclude all requests starting with /wp-admin/
RewriteCond %{REQUEST_URI} !^/wp-admin/.*$
RewriteRule ^(.*) /de/$1? [L,R=301]
</IfModule>

So you can consider the issue resolved. Thanks again for your time and efforts!

Kind Regards,
Andreas

August 8, 2019 at 7:38 am #4360407

Radu
Supporter

Languages: English (English )

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

Hey Andreas,

I'm glad to hear that the code you added to the .htaccess file did the trick about the redirect. Also, thank you for sharing the code that you used. This way, other users will be able to use it in order to achieve this.

I'll mark this ticket as resolved now. If you have any other issue or question, please open a new ticket and we'll have a look at it.

Thanks,
Radu