【问题标题】:Geographically change domain keeping URL same地理上更改域保持 URL 相同
【发布时间】:2013-06-06 09:14:03
【问题描述】:

我正在使用此脚本根据用户的 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
}
?>

【问题讨论】:

    标签: php redirect geoip


    【解决方案1】:

    $_SERVER['REQUEST_URI'] 添加到您的重定向中。

    header("Location: $url/$_SERVER[REQUEST_URI]");
    

    【讨论】:

    • header('位置:'.$url/$_SERVER['REQUEST_URI']);对吗?
    猜你喜欢
    • 1970-01-01
    • 2015-04-09
    • 1970-01-01
    • 1970-01-01
    • 2018-03-21
    • 2011-05-25
    • 2020-05-15
    • 2015-02-13
    • 1970-01-01
    相关资源
    最近更新 更多