我的情况是,我有一个多站点设置,在那里我使用不同语言的子目录。我使用英语的主主页和其他语言的子目录,如下所示:
Mywesmite。com:英文frontpage
我的网站。com/jp/:日文frontpage
我想做什么我想把住在日本的人重定向到日文首页without using a WordPress plugin.
我使用geoplugin.com , 灵感来自3rd answer of this stack 我编辑了主题header.php
通过在最开始添加以下内容
$a = unserialize(file_get_contents(\'http://www.geoplugin.net/php.gp?ip=\'.$_SERVER[\'REMOTE_ADDR\']));
$countrycode= $a[\'geoplugin_countryCode\'];
if ($countrycode==\'JP\'){
header( \'Location: https://mywebsite.com/jp/\' );
exit;
}
然而,我得到了以下错误页面未正确重定向
连接到mywebsite时出错。com。
此问题有时可能是由于禁用或拒绝接受Cookie造成的。
Note: 例如,重定向可以在外部网站上正常工作
$a = unserialize(file_get_contents(\'http://www.geoplugin.net/php.gp?ip=\'.$_SERVER[\'REMOTE_ADDR\']));
$countrycode= $a[\'geoplugin_countryCode\'];
if ($countrycode==\'JP\'){
header( \'Location: https://anotherwebsite.com\' );
exit;
}
有没有办法修复此错误?我也愿意接受其他不使用WP插件的解决方案。