How Weglot manages redirections

In this article, you will learn more about how Weglot manages redirections on your website.



Note: In this article, we will use "301 redirection." 301 means that a redirection is permanent.

1. Redirections without Weglot

Firstly, we can take a look at how redirections work without using Weglot.


On WordPress, if you create a page /about-us . Then decide to change this URL to /about .

Now, when you go on /about-us you have a 404 error page.

⇒ By default, there is no 301 redirection on WordPress.

However, you can use "Yoast Premium" or "Redirection" plugins to create a 301 redirection from /about-us to /about .

Once done, when you go on /about-us you will be redirected to /about .


Let's see how it works when you are using another tool than WordPress (Shopify is used here for the example).

When changing a URL on Shopify, you can choose (with a checkbox, see screenshot) if you want to create a redirection :

If you check the box, then go to /about-us you will be redirected to /about .


2. I am using Weglot's plugin for WordPress

If you have a redirection: /a/b

Then going on /fr/b will show the French page; however, going to /fr/a will redirect to /b and NOT /fr/b .

To have /fr/a redirect to /fr/b, you can try to add this filter (through the plugin Code Snippet):

add_filter( 'wp_redirect', 'wp_redirect_weglot', 0, 2 );
function wp_redirect_weglot( $url, $status ) {
    if ( function_exists( 'weglot_get_current_language' ) ) {
        $cl = weglot_get_current_language();
        $ol = weglot_get_original_language();
        $request_url_service = weglot_get_service( 'Request_Url_Service_Weglot' );
        $language_service    = weglot_get_service( 'Language_Service_Weglot' );

        if ( $cl !== $ol && strpos( $url, '/' . $cl . '/' ) === false ) {
            $u = $request_url_service
                    ->create_url_object( $url )
                    ->getForLanguage( $language_service->get_language_from_internal( $cl ) );
            if ( $u === false || empty( $u ) ) {
                return $url;
            }

            return $u;
        }
    }

    return $url;
}

3. I am using another Weglot integration


To know if you are using a JavaScript integration or a subdomain/subdirectory integration, you can go to your Weglot dashboard > Go to your project > "Setup" page > Take a look at the "Subdomains or Subdirectories" toggle.

If it is switched on, it means that you are using a subdomain/subdirectory integration:

If it is switched off, it means that you are using a JavaScript integration.


a. I have a JavaScript integration

As the translation is done browser side without a specific URL, it will work. Meaning that if you go on /a , you will be redirected to /b and then it will translate when you are on /b .


b. I have a subdomain/subdirectory integration

The subdomain and subdirectory integrations keep the redirections, which means that if you have a redirection: /a/b and then go to es.site.com/a , you will be redirected to es.site.com/b .

The same also holds for subdirectories.


If you have any difficulties with redirections on your translated versions, you can contact us directly at support@weglot.com.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us