0
我有我的WordPress网站托管在nginx服务器上。现在,我创建了一个子域名称us.example.com当我们在美国开放的网站,例如us.example.com,我怎样才能根据国家/地区更改WordPress网址?如何更改域名根据国家明智的wordpress
我有我的WordPress网站托管在nginx服务器上。现在,我创建了一个子域名称us.example.com当我们在美国开放的网站,例如us.example.com,我怎样才能根据国家/地区更改WordPress网址?如何更改域名根据国家明智的wordpress
有一个网站,提供一个给定的IP定位技术(实际上有很多,但我将只专注于这一个):http://ip-api.com/
可以使用他们为了提供信息,以重定向访问者相应的子域这样的:
$this_ip = $_SERVER["REMOTE_ADDR"];
$get_ip_info = file_get_contents("http://ip-api.com/json/".$this_ip);
$ip_info = json_decode($get_ip_info);
$countryCode = strtolower($ip_info->{"countryCode"});
header("Location: http://".$countryCode.".example.com");
当然,也有许多国家,自实际上不可能保持为每一个子域,您可以使用“如果”语句来缩小重定向选项:
if($countryCode=="fr"){ //french
header("Location: http://fr.example.com");
}else
if($countryCode=="de"){ //german
header("Location: http://de.example.com");
}else
if($countryCode=="gr"){ //greek
header("Location: http://gr.example.com");
}else{ //universal
header("Location: http://www.example.com");
}
希望这可以帮助你!
它不工作,当我们将其重定向到子域时,网站没有打开。实际上 –
如果您直接访问(例如)de.example.com,该网站可以正常工作,但是如果您使用我的脚本去那里不工作?你是这个意思吗? –
首先尝试“回显”变量“countryCode”。然后确保项目中存在与该值相对应的子域... –