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
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;
}
});
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.
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.
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.
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);
}
});
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.