Replace URL

Hi everyone,
I need your support with the following issue.

I have an URL (e.g. https://www.domain.com/blogpost) and I want to replace this URL with the corresponding subdomain (e.g. https://www. en. domain.com/blogpost) as soon as someone hits a button. (The subdomain is the english version of my original website)

First I tried…

import wixLocation from 'wix-location';

let url = 'en.' + wixLocation.url 

…but than the prefix ‘en.’ appears in front of https:// and not after www.

Do you have any suggestions what I need to change so that I get the right result?

Thanks for your help!
Alex

Hi Alex,
You can try this:

const url = wixLocation.url; 
const url1 = url.slice(0, 12);
const url2 = url.slice(11);
const newUrl = url1 + 'en.' + url2;

Good luck!
Roi

Hi Roi,
awesome, that´s what I´ve been looking for!

Thank you!