我已经为此工作了一个星期,并用我的 .htaccess 文件进行了尝试,但即使这样在火狐中基本上不起作用,它说......
页面未正确重定向 Firefox 检测到 服务器正在重定向对此地址的请求,其方式将 永远不会完成。 此问题有时可能是由于禁用或拒绝访问 Cookie 引起的。
在铬中它的说法.....
此网页具有重定向循环 该网页位于 https://www.website.com/row/index.php 导致了太多 重 定向。清除本网站的 Cookie 或允许第三方 Cookie 可能会解决问题。如果不是,则可能是服务器 配置问题,而不是您的计算机问题。
我从Maxminds网站的GeoIP php API上传了GeoIP.dat和geoip.inc文件到我主机上的一个目录,然后我使用以下php代码块编辑了我的index.php文件。
<?php
require_once("geoIP/geoip.inc");
$gi = geoip_open('geoIP/GeoIP.dat', GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
// prints the country code your visitor is in
$my_countriesrow = array('AD','AE','AF','AG','AI'.....ect);
$my_countrieseuro = array('AN','AT','BA','BE','BG','BY','CH'.....ect);
/* $my_country = array('GB','UK'); */
if (!in_array(strtolower($country), $my_countriesrow)) {
header('Location: https://www.website.com/row/index.php');
exit();
}
else if(!in_array(strtolower($country), $my_countrieseuro)){
header('Location: https://www.website.com/euro/index.php');
exit();
}
else {
header('Location: https://www.website.com/index.php');
exit();
}
// the end
geoip_close($gi);
?>
我认为这可能与我的 .htaccess 文件有关,因为它包含其中的这个......
# Make all requests have www in them
RewriteEngine On
RewriteCond %{HTTP_HOST} ^website'.com
RewriteRule ^(.*)$ https://www.website.com$1 [R=permanent,L]
不知道还能做什么,已经把我所有的头发都拔掉了! 非常感谢ADVACE的家伙!
问候-菲 利 普
已更新
假设此代码包含在"https://www.website.com/row/index.php"中
如果我从 BE 访问此页面,将触发第一个 if 语句,并一遍又一遍地将我带到同一页面。
更新:
像这样的事情可能会阻止循环:
require_once("geoIP/geoip.inc");
$gi = geoip_open('geoIP/GeoIP.dat', GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
$my_countriesrow = array('AD','AE','AF','AG','AI');
$my_countrieseuro = array('AN','AT','BA','BE','BG','BY','CH');
/* if you got redirected, do not redirect again */
if (!isset($_GET['redirected'])) {
if (!in_array(strtolower($country), $my_countriesrow)) header('Location: https://www.website.com/row/index.php?redirected');
else if(!in_array(strtolower($country), $my_countrieseuro)) header('Location: https://www.website.com/euro/index.php?redirected');
else header('Location: https://www.website.com/index.php?redirected');
}
geoip_close($gi);