Php 如何根据国家/地区重定向到文件
我使用不同的网站目录根据国家为我的公司喜欢 Getacho.com Getacho.com/pk/ Getacho.com/uk/ Getacho.com/ca/ 我正在使用一个脚本。因为我是从巴基斯坦来的 Getacho.com 我重定向到 Getacho.com/pk 但问题是当我打开时 Getacho.com/about.php 我没有重定向到 Getacho.com/pk/about.php 这是执行第一次重定向的脚本代码:Php 如何根据国家/地区重定向到文件,php,Php,我使用不同的网站目录根据国家为我的公司喜欢 Getacho.com Getacho.com/pk/ Getacho.com/uk/ Getacho.com/ca/ 我正在使用一个脚本。因为我是从巴基斯坦来的 Getacho.com 我重定向到 Getacho.com/pk 但问题是当我打开时 Getacho.com/about.php 我没有重定向到 Getacho.com/pk/about.php 这是执行第一次重定向的脚本代码: <?php require_once('geoplugi
<?php
require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();
// create a variable for the country code
$var_country_code = $geoplugin->countryCode;
// redirect based on country code:
if ($var_country_code == "US" OR $var_country_code == "UM") {
header('Location: http://www.getacho.com/');
}
elseif($var_country_code == "PK") {
header('Location: http://www.getacho.com/pk/');
}
elseif($var_country_code == "AE") {
header('Location: http://www.getacho.com/ae/');
}
elseif($var_country_code == "CA") {
header('Location: http://www.getacho.com/ca/');
}
elseif($var_country_code == "GB") {
header('Location: http://www.getacho.com/uk/');
}
elseif($var_country_code == "IN") {
header('Location: http://www.getacho.com/in/');
}
?>
因为您使用的是Apache,所以可以使用服务器变量REQUEST_URI来获取请求的url。然后简单地将其添加到url中:
if ($var_country_code == "US" OR $var_country_code == "UM") {
header( "Location: http://www.getacho.com{$_SERVER['REQUEST_URI']}" );
} elseif($var_country_code == "PK") {
header( "Location: http://www.getacho.com/pk{$_SERVER['REQUEST_URI']}" );
} elseif( ... ) {
//etc
}
我正在使用两个文件。就像你能看到的一样你在用什么httpdeamon?阿帕奇?nginx?iis?lighttpd?“还有别的吗?”西蒙尼·尼格罗。我看到了。但是我的服务器上没有安装mod_geoip。我使用简单的主机。