Necesito ayuda con la redirección a subdominios. Con IPinfo obtengo el país del visitante, luego lo redirijo a uno de mis subdominios y necesito que se vea como ua.mysite o kz.mysite o ru.mysite Intenté window.location.href = data.country + 'mysite' pero esto no funcionó ¡Espero que puedas ayudarme! :)
// Let's check if we have the value in localstorage if (localStorage.getItem('country') == 'RU') { // Already have the value in localStorage no need to make call to IPinfo window.location.hostname = 'ru.mysite.tech' } else if(localStorage.getItem('country') == 'KZ') { // Already have the value in localStorage no need to make call to IPinfo window.location.hostname = 'kz.mysite.tech' } else if(localStorage.getItem('country') == 'UA') { // Already have the value in localStorage no need to make call to IPinfo window.location.hostname = 'ua.mysite.tech' } else{ // No cached data, let's get it from IPinfo fetch('https://ipinfo.io/json?<MyToken>') .then(res => res.json()) .then(data => { if(data.country == 'UA'){ localStorage.setItem('ipinfo', data.country) window.location.hostname = 'ua.mysite.tech' } else if(data.country == 'KZ'){ localStorage.setItem('ipinfo', data.country) window.location.hostname = 'kz.mysite.tech' } else { localStorage.setItem('ipinfo', data.country) window.location.hostname = 'ru.mysite.tech' } }) } }```Las actualizaciones de window.location.hostname no causan redirección.
Debe actualizar window.location directamente de esta manera (tenga en cuenta el "https:/"):
if (localStorage.getItem('country') == 'RU') { // Already have the value in localStorage no need to make call to IPinfo window.location = 'https://ru.mysite.tech' }