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.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 -
- 12:00 – 16:00 12:00 – 16:00 12:00 – 16:00 12:00 – 16:00 12:00 – 16:00 -

Supporter timezone: Europe/Zagreb (GMT+02:00)

Tagged: 

This topic contains 9 replies, has 0 voices.

Last updated by wernerT-3 1 week, 3 days ago.

Assisted by: Dražen.

Author Posts
March 3, 2025 at 9:26 pm #16770926

wernerT-3

Background of the issue:
I have upgraded from WPML v4.6.3 to v4.7.1 and now the redirection for my connected languages homepage is different. The homepage for the default language (default = en) can now be reached under: /en and /en/, which is OK. But the connected homepage for other languages like DE + FR can now only be reached like /de and /fr but not anymore under /de/ and /fr/ - those last to redirect to /de and /fr. Note that hidden link is my development domain not accessible to the outside - it is the local development for hidden link. On the production site: hidden link still the old version is running and does support /fr/ and /de/. I did turn off all other plugins except for WPML v4.7.1 - no other plugin is running. I also switched theme to the standard WordPress Twenty Twenty Five v1.1 theme. On the link to the page you can see WPML v4.6.3 running that does correctly show the German connected homepage on /de/. Link to a page where the issue can be seen: hidden link

Symptoms:
The country languages can only be seen on /de and /fr instead of /de/ and /fr/ as expected.

Questions:
Why does the redirection for connected language homepages differ after upgrading to WPML v4.7.1?
How can I make the country language homepages reachable with a trailing slash like /de/ and /fr/?

March 5, 2025 at 10:44 am #16777860

Dražen
Supporter

Languages: English (English )

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

Hello,

Thanks for contacting us.

I just checked on the test site with the same settings/permalinks, and it works just fine with the latest WPML 4.7.1, so it could be something specific to your environment/website.

Please create and share a staging site where we can check this issue further. I have enabled private reply.

Thanks,
Drazen

March 5, 2025 at 10:47 am #16777882

Dražen
Supporter

Languages: English (English )

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

Hello,

you also say: "But the connected homepage for other languages like DE + FR can now only be reached like /de and /fr but not anymore under /de/ and /fr/ - those last to redirect to /de and /fr"

But if I check your live website is see that /en redirect to /en/, so not sure what is expected behaviour for you on live / staging site.

Regards,
Drazen

March 5, 2025 at 12:23 pm #16778414

wernerT-3

Hi Drazen,

Let me first reply to you last question: "so not sure what is expected behaviour"

The expected behavior, which works up to at least 4.6.3 (and not anymore already in 4.6.8 - see previous ticket) - is that homepages can be reach under the URL with a slash at the end. Like /de/ and /fr/ - this does work for /en/ in the new version but only for the default language ( EN is default language ) and not for any language.

On the Live site in our .htaccess file we redirect from /fr , /de , /en to respectively /fr/ , /de/ , /en/

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

In your first reply you state: "it works just fine" , but in your second reply you state "not sure what to expect".
Now I wonder about your first reply, what does work fine?
On your test site can you view any language homepage on /xx/ ( so, with trailing-slash ) ?
Since I do know that it does work for the default language, just not for the other languages.

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

Since it is impossible to grand sftp access due to IP restrictions, I can only give you access to our staging environment and that iis already hard to do as this is a controlled environment connected to GitLab for deployments with separate .htaccess + wp-config.php deployments and connections - with specials connections NFS files for uploads and other shares.

It would be much easier if we can setup a teams-call and I share my screen which you can takeover.

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

A side-effect that I noticed is that the function "url_to_postid" neither works for these homepages:

Failed to resolve URL: hidden link
Failed to resolve URL: hidden link
Failed to resolve URL: hidden link
Failed to resolve URL: hidden link
Resolved URL: hidden link to ID: 2
Resolved URL: hidden link to ID: 12778
Failed to resolve URL: hidden link
Failed to resolve URL: hidden link
Resolved URL: hidden link to ID: 5827
Resolved URL: hidden link to ID: 14636

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

I did find a work-around for wpml redirecting /de/ ( or /fr/ ) back to /de or /fr

This is my work-around:
function check_wordpress_redirects($redirect_url, $requested_url)
{
if ($redirect_url . "/" === $requested_url) {
$parsed_url = parse_url($redirect_url);
$path_info = pathinfo($parsed_url["path"]);
if($path_info["dirname"]=="/"){
return false;
}
}
return $redirect_url;
}

add_filter('redirect_canonical', 'check_wordpress_redirects', 99, 2);

In local dev I use global.it.atos.net as the domain for atos.net (prod live site)
For a homepage request for "hidden link", the $redirect_url reads:
"hidden link" - so I then make a check to see if adding the slash to the redirect is the same as the requested, then I check if this is happening inside the "root" of the site, so only for /xxxx and not any subfolder - and if so, just cancel the redirect "return false".
Now the homepage for /de/ does show correctly.

When I would even invest time actually debug wpml code I might be able to pinpoint where your redirection doing this for /fr/ and /de/ but not for /en/ ...
Next I would need revert to 4.6.3 and see why it does work correctly in that version.
But I guess I become a wpml developer ;-)))

I hope this clarifies the issue more clearly and you will be able to replicate this behavior on you side. If not, if you can reach your language homepage with slash at the end, then there might be something wrong with the database content. since I never created a clean install.

If you like to setup teams call that would be welcome as well. Just propose a date/time.

Kind regards,
Michel Waaijer ( on behalf of Ralph / Atos )

March 5, 2025 at 12:50 pm #16778631

Dražen
Supporter

Languages: English (English )

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

Hello Michel,

Thanks for the detailed reply; it is really helpful.

I was able to reproduce the issue and confirm your findings. I have now escalated this issue to our 2nd tier to check and escalate it further.

I will update you when I have some news, it may take a day or two.

Regards,
Drazen

March 26, 2025 at 12:03 pm #16862478

Dražen
Supporter

Languages: English (English )

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

Hello,

thanks for the patience.

Our 2nd tier checked, and our opinion is that since the trailing slash is removed from permalinks, both languages should redirect to no slash. The results should be consistent.

That's what we will try to fix.

As for your case, you could add the following code (to functions.php or via Code Snippets) to strip the callback we add to the redirect_canonical filter so that the results will be the same as "do nothing".

add_action( 'init', function() {
    global $wp_filter;

    $hook_name = 'redirect_canonical';
    $priority  = 10;
    $method    = 'prevent_redirection_of_frontpage_on_secondary_language';

    if ( 
        isset( $wp_filter[ $hook_name ] ) 
        && is_a( $wp_filter[ $hook_name ], 'WP_Hook' ) 
    ) {
        $hook = $wp_filter[ $hook_name ];

        // Make sure this priority exists
        if ( isset( $hook->callbacks[ $priority ] ) ) {
            foreach ( $hook->callbacks[ $priority ] as $unique_id => $callback_data ) {
                $callback = $callback_data['function'] ?? null;

                // The callback is likely [someObject, '...the callback name...']
                if ( is_array( $callback ) ) {
                    [ $object_or_class, $callback_method ] = $callback;

                    // If the method name matches, remove it
                    if ( $callback_method === $method ) {
                        unset( $hook->callbacks[ $priority ][ $unique_id ] );
                    }
                }
            }
        }
    }
});

Regards,
Drazen

March 28, 2025 at 2:09 pm #16873395

wernerT-3

Hello Drazen,

Since that you and your 2nd line support only have an "opinion", you better consult with someone who has authority to change the application and also the manuals.

From the 1st screenshot in this thread (and my newly uploaded), you can clearly see that the language homepages should be accessible with the trailing slash ! This has always been the case, up to v4.6.3 after which it did not work anymore - but this due some coder not knowing the manual - since it was never introduced as a Structural Change.

The coding sample you give, probable will fix the issue of redirection but will not correct the function "url_to_id" nor will it fix "home_url".
For all 3, the redirecting, url_to_id and the home_url I already have my own fixes - since I upgraded to the latest version and will not change our complete site structure due to a bug on your side.

Please escalate the issue. If then it really is decided to leave the bug as it is, then you will need to change the manuals as well and I will keep using my own fixes.

Kind regards,
Michel Waaijer

07-Language-settings-2025-03-28.jpg
March 28, 2025 at 2:20 pm #16873432

Dražen
Supporter

Languages: English (English )

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

Hello Michel,

Thanks for getting back.

Sure, I will share your comment with our 2nd tier and our devs, and we will let you know the reply.

Regards,
Drazen

March 31, 2025 at 8:29 am #16877997

Dražen
Supporter

Languages: English (English )

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

Hello,

please note that issue is escalated to our developers, and based on the provided info it will be decided which approach is correct. The issue is in the queue and it will take some time before we have a proper permanent fix.

As for the screenshot, the example URLs don't appear to take account of the permalink settings but instead are based on the default permalink pattern, which does include a trailing slash. If needed, we will address this.

Anyway, once I have more info from developers or a permanent fix is released, I will share it with you.

Regards,
Drazen

April 1, 2025 at 7:37 am #16881636

wernerT-3

Hello Drazen,

Thank you for escalating the issue for a proper resolve. Do note that the trailing slash is only for homepages, not for any other page ! You can also have your default homepage on / (root) of your site (which neither has a name) we just choose to always display the language channel as this increases the security of the site hugely.
The permalink structure as defined in "Settings -> Permalinks -> Permalink Structure" , is there for post-type Post, since WordPress originally started as a "blog" platform not for post-type Page. Other custom post-types can have their own "Rewrite" rules.

Kind regards,
Michel