admin管理员组文章数量:1122832
I have a WP question hoping someone can point me in right direction.
I need to redirect my store customers to a specific country subdomain for all pages, posts, and products. The main domain and subdomain have the same content, so I only need to change the URL.
For Example: www.example main page www.example/page1 , www.example/product1
For US visitor: us.example main page us.example/page1 , us.example/product1
For UK visitor: uk.example main page uk.example/page1 , uk.example/product1
Thank you.
I have a WP question hoping someone can point me in right direction.
I need to redirect my store customers to a specific country subdomain for all pages, posts, and products. The main domain and subdomain have the same content, so I only need to change the URL.
For Example: www.example.com main page www.example.com/page1 , www.example.com/product1
For US visitor: us.example.com main page us.example.com/page1 , us.example.com/product1
For UK visitor: uk.example.com main page uk.example.com/page1 , uk.example.com/product1
Thank you.
Share Improve this question edited Jul 24, 2024 at 20:04 Tony Djukic 2,2594 gold badges18 silver badges33 bronze badges asked Jul 24, 2024 at 1:29 ParadivaParadiva 1 1- you can do this with the help of the polylang plugin wordpress.org/plugins/polylang – mmm Commented Jul 24, 2024 at 2:57
1 Answer
Reset to default 0You can try to check the visitor country via the geojs.io, and then build the logic for redirecting.
See the JS code below:
geoTargeting();
function geoTargeting() {
return new Promise((resolve, reject) => {
fetch('https://get.geojs.io/v1/ip/country.json').then(response => response.json()).then(data => {
const currentHostname = window.location.hostname;
const currentPath = window.location.pathname;
let newUrl;
if (data.country === 'US') { // Check if country US
const subdomain = 'us';
newUrl = window.location.protocol + '//' + subdomain + '.' + currentHostname + currentPath;
window.open(newUrl); // Redirect
} else {
resolve(false);
}
}).catch(error => {
console.error('Error:', error);
resolve(false);
});
});
}
本文标签: url rewritingRedirect all URLs in WordPress and Permalink to by country to subdomain
版权声明:本文标题:url rewriting - Redirect all URLs in WordPress and Permalink to by country to subdomain 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736299980a1930650.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论