简体   繁体   English

如何根据国家/地区明智地重定向到文件

[英]How to redirect to file according to country wise

I am using different sites directories according to countries for my company like 我正在为我的公司根据国家使用不同的网站目录

Getacho.com Getacho.com
Getacho.com/pk/ Getacho.com/pk/
Getacho.com/uk/ Getacho.com/uk/
Getacho.com/ca/ Getacho.com/ca/

I am using one script. 我正在使用一个脚本。 As I am from pakistan when I open 当我打开时来自巴基斯坦

Getacho.com Getacho.com

I redirect to 我重定向到

Getacho.com/pk Getacho.com/pk

but the problem is when I open. 但是问题是当我打开时。

Getacho.com/about.php Getacho.com/about.php

I do not redirect to 我没有重定向到

Getacho.com/pk/about.php. Getacho.com/pk/about.php。


This is the script the code that does the first redirect: 这是执行第一次重定向的脚本代码:

<?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/');
}
?>

Since you are using Apache, you can use the server-variable REQUEST_URI to get the requested url. 由于使用的是Apache,因此可以使用服务器变量REQUEST_URI来获取请求的URL。 Then it is simply adding that to the 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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM