Redirecting pages in secondary language

How to redirect pages in the secondary language site?

Product:
Wix URL Redirect Manager
Wix Multilanguage

What are you trying to achieve:
We can’t change the URL’s from our secondary language sites.
They are just the primary URL with a language tag.
To work around this issue, I want to install redirects, so links from our previous site (WordPress) will be redirected to the new one (because I can’t make the URL’s the same).

What have you already tried:
I have tried to install redirects. But the Wix URL Redirect Manager keeps simplifying my URLs.

For example, I enter: website.be/?lang=fr
It changes to: website.be

Which completely defeats the purpose…

1 Like

If you add a little bit of code to your site, it can be done easily.
I’ll be here to guide you if you’re willing to give it a shot.

1 Like

Hi, I would love some help with this as I am not experienced. Thank you!

  1. From your site editor, and turn on Dev Mode from the panel at the top.
  2. You should now see a Page Code panel to your left.
  3. At the bottom of the page list, you should see an option called masterpage.js.
  4. Click on it to open up the code panel at the bottom.
  5. Once opened, clear all the code and paste this inside the code panel.
  6. Once that is done, Publish your site.

Code:

import wixLocationFrontend from 'wix-location-frontend';
import wixWindowFrontend from 'wix-window-frontend';

$w.onReady(function () {

    const query = wixLocationFrontend.query

    if (query.lang) {
        const lang = query.lang;
        wixLocationFrontend.queryParams.remove(["lang"]);
        wixWindowFrontend.multilingual.currentLanguage = lang;
    }
});

import wixLocationFrontend from ‘wix-location-frontend’;
import wixWindowFrontend from ‘wix-window-frontend’;

$w.onReady(function () {
    const query = wixLocationFrontend.query
    //FIRST GETTING THE LANG-VAULE! --> then using it inside your code.
    let lang = query.lang;

    if (lang) {        
        if(lang==='fr') {console.log('FRENCH language detected')}
        if(lang==='en') {console.log('ENGLISH language detected')}
        if(lang==='de') {console.log('GERMAN language detected')}
        
        wixLocationFrontend.queryParams.remove(["lang"]);
        wixWindowFrontend.multilingual.currentLanguage = lang;
    }
});

And so on…

Hi, Thank you for the info. I did this but it did not change the problem.
Am I supposed to change the code to my specific situation?

Can you provide a screenshot of where you’ve inserted your code?

The code and the placement seem to be correct.

Publish your site once again and try viewing it from Incognito or a different browser?
It can take. a couple of minutes for the changes to reflect on the live site.

Also make sure that the language is added to the Wix Multilingual first.

If the URL ends with ?lang=de and German isn’t added in Wix Multilingual, it won’t work.

I added the code to one of my own multilingual sites and it works perfectly.
But sometimes the code that you add takes a while to show up since your pages are cached in your browser. So it is recommended viewing it from Incognito or a different browser so that there is no cache.

Thank you.

Could you explain to me how exactly this code resolves the issue?

Here’s a breakdown of the entire code:

This imports the necessary scripts. wixLocationFrontend is used to fetch and set the site URL, and wixWindowFrontend allows us to change the language of the site, using Wix Multilingual.

This fetches the query form the end of the URL. (i.e. ?lang)

If the query “lang” exists in the URL, it stores it’s value inside a variable and the query is removed from the end of the URL.

Finally, the language is fetched from the variable and the current language of the site is changed, based on the value of the lang query.

Did the code resolve the issue?

I don’t think this code will help me with the redirects in Wix URL Redirect Manager.
Or maybe I just don’t understand?

This code simply helps you set the language of the site based on your URL endpoint.
Isn’t that what you’re trying to achieve?

No, sorry if I was not clear.
I have an issue with creating redirects in the Wix URL Redirect Manager.

In the sites main language, English, the URL’s are okay but, in the secondary language, French, the URL is the same as in the main language + the language tag. I have asked support and we can not change this. They advised to use Redirects. Because, we have links and QR-codes with the URL’s in French.

But the redirect manager also has issues with multilingual sites.

I’ll give a little example.

Main language: English
URL: mysite/events.com

Secondary language: French
URL: mysite.com/evenements/?lang=fr

That is how it should be.
But now in Wix, the URL is: mysite/events/?lang=fr
This is just the link in main langue + language tag.

So, I would need a redirect from
From: mysite.com/evenements/?lang=fr
To: mysite/events/?lang=fr

But the Wix URL redirect editor will not accept these URL’s.

Okay the example seems to explain the issue.

I’ve provided the code for a custom redirect manager for your site, and this works even with the query params that the Wix URL Redirector does not accept.

Replace the previous code with the new one I’ve provided, and you can add as many url redirects to the list as you want. Just make sure that the punctuation is correct and the URLs start with https://

Code:

import wixLocationFrontend from 'wix-location-frontend';

const redirectList = [{
        main: "https://mysite.com/evenements/?lang=fr",
        redirect: "https://mysite/events/?lang=fr"
    },
    {
        main: "https://mysite/a-propos/?lang=fr",
        redirect: "https://mysite/about/?lang=fr"
    },
]

$w.onReady(function () {

    const url = wixLocationFrontend.url;
    let index = -1;

    redirectList.forEach((item, i) => {
        if (item.main === url) {
            index = i;
        }
    });

    if (index !== -1) {
        const redirectUrl = redirectList[index].redirect;
        wixLocationFrontend.to(redirectUrl);
    }

});
1 Like

No, that is not what she explained.

She is trying to redirect old Wordpress URLs to new Wix URLs.

They both contain language tags so the Wix URL redirect is not allowing her to save the redirect correctly.

Hey @codequeen, great to see you back on the forum!

Could you provide a solution to this?
It’ll help her as well as me. I’m self taught and I’d also like to know how can this be resolved.

I don’t know if this is any help but, the reason that the Wix URL Redirect Manager does not work is because it trims the URL’s domain. When it does that, It also trims the language tag.

I think the system is not adapted to multilangual sites.

You will have to try the import feature, and if it doesn’t work only Wix Support can assist you.

Maximum is 500 at one time.
Maximum is 5,000 total per site.
Anything with a # symbol will not work.

1 Like