Skip Navigation

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 topic contains 4 replies, has 3 voices.

Last updated by Lucas Vidal de Andrade 3 months ago.

Author Posts
January 24, 2024 at 12:33 am #15219303

gabrielS-38

Tell us what you are trying to do?

I need to redirect my production blog urls to the new WPML urls. The urls will be ALMOST the same. the difference is the language code. On My current production site, portuguese is like this: /pt_BR/ while in WPML is like this /pt-br/

example:

actual url in portuguese in my live production site:
hidden link

new WPML url in portuguese in my local developing site:
hidden link

I want to use a custom .htaccess rule, to redirect every page that has /pt_BR/ on the url, to the same exact url, but with the /pt-br/ code instead. On my new local development WPML site I am testing this. I created the following post in english (default), and in portuguese as well:

english: hidden link
portuguese: hidden link

Then I typed the portuguese url, but with my production site lang code, just to try if the redirection is working:

hidden link

and for some reason, I am redirected to the english (default) post url:
hidden link

Why is this? I deleted my .htaccess rule because and redirection to english slug continues.
WPML redirection is turned off as well (see image please).

What I would expect:
My .htaccess redirects to WPML portuguese url, or at least, display 404.

Is there any documentation that you are following?
no.

Is there a similar example that we can see?
no

What is the link to your site?
is local develpment at the time of writting, I can't provide a public link.

wpml.png
January 24, 2024 at 7:22 am #15219932

Sumit
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi,

Thank you for contacting the support forum.
Before your ticket is assigned to one of my colleagues, please allow me to walk you through some initial debugging steps. This will help speed up the support process.

The redirect might be coming from WP, redirecting to the correct post based on a slug.

To bypass this you can place your redirect rule on the top of htaccess file before WP rules. Thus it will redirect pt_BR request to pt-br even before passing the request to WP rules.

Thanks

January 24, 2024 at 8:14 am #15220075

gabrielS-38

Hi Sumit, thank you for your quick answer.
Your suggestion is a good idea. Unfortunately, I have tried with the following two examples, and the redirection to the english post remains:

1.
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/pt_BR/(.*)$ $1/pt-br/$2 [R=301,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

2.
<IfModule mod_rewrite.c>
RewriteRule ^(.*)/pt_BR/(.*)$ $1/pt-br/$2 [R=301,L]
</IfModule>
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Please, do not respond to email. Thank you.

January 24, 2024 at 8:18 am #15220083

gabrielS-38

By the wat, I don't think there is any rewritte condition on that .htaccess (besides the one that I added). That makes me think that the redirection might me comming from WPML?

January 24, 2024 at 12:15 pm #15221645

Lucas Vidal de Andrade
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi,

Thank you for trying out the .htaccess modifications and sharing the detailed information. It's helpful in narrowing down the potential causes. Considering that the .htaccess changes didn't produce the desired result, there are a few additional aspects we can look into:

1. WordPress has its own redirection mechanisms, especially for canonical URLs, which might be overriding your .htaccess rules. This could be the reason why the request is being redirected to the English version of the post.

2. If you have any caching implemented (either via a plugin or server-level), try clearing it. Also, go to the WordPress admin panel, navigate to "Settings" > "Permalinks", and just click "Save Changes" to reset the permalinks. This sometimes resolves unexpected redirection issues.

3. If you're comfortable with PHP, you could add a small snippet at the top of your theme's functions.php file to handle this redirection. This would bypass .htaccess and WordPress's default behavior, ensuring your specific rule is executed first. Check this documentation:
https://developer.wordpress.org/reference/functions/wp_redirect/

Since the site is still in a local development environment, it's a good opportunity to experiment with these suggestions without affecting the live site. Please try these steps and let us know how it goes. We're here to assist you further if needed.

Best Regards,

gabrielS-38 confirmed that the issue was resolved on 2024-01-31 02:08:06.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.