Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在地理位置上更改域,保持URL不变_Php_Redirect_Geoip - Fatal编程技术网

Php 在地理位置上更改域,保持URL不变

Php 在地理位置上更改域,保持URL不变,php,redirect,geoip,Php,Redirect,Geoip,我正在使用此脚本根据用户的IP重定向用户。 但问题是它重定向到主页,或者只重定向到我在脚本中指定的URL。我怎样才能在保持URL不变的情况下更改域?例如,site.com/whateverpage重定向到site.au/whateverpage <?php // Next two lines are for Beyond Hosting // Don't forget to change your-domain require_once '/home/your-domain/php/Net

我正在使用此脚本根据用户的IP重定向用户。 但问题是它重定向到主页,或者只重定向到我在脚本中指定的URL。我怎样才能在保持URL不变的情况下更改域?例如,site.com/whateverpage重定向到site.au/whateverpage

<?php
// Next two lines are for Beyond Hosting
// Don't forget to change your-domain
require_once '/home/your-domain/php/Net/GeoIP.php';
$geoip = Net_GeoIP::getInstance('/home/your-domain/php/Net/GeoIP.dat');

// Next two lines are for HostGator
require_once 'Net/GeoIP.php';
$geoip = Net_GeoIP::getInstance('GeoIP.dat');

try {
  $country = $geoip->lookupCountryCode($_SERVER['REMOTE_ADDR']);

  switch((string)$country) {
    case 'AU':
      $url = "http://www.site.au";
      break;
    case 'CA':
      $url = "http://www.site.ca";
      break;
    default:
      $url = "http://site.com";
  }

  if (strpos("http://$_SERVER[HTTP_HOST]", $url) === false)
  {
      header('Location: '.$url);
  }
} catch (Exception $e) {
  // Handle exception
}
?>

$\u服务器['REQUEST\u URI']
添加到重定向中

header("Location: $url/$_SERVER[REQUEST_URI]");
标题('Location:'.$url/$\u服务器['REQUEST\u URI']);是这样吗?