【问题标题】:How to overide the geo IP Redirect如何覆盖 geoIP 重定向
【发布时间】:2014-11-15 20:19:36
【问题描述】:

我目前在我的 htaccess 中设置了地理重定向,以将访问 example.com 的亚洲用户重定向到 asia.example.com。我现在想知道如何覆盖该重定向,以便来自 asia.example.com 的用户可以通过 asia.example.com 上的链接访问 example.com。

这可能吗?或者我必须使用客户端重定向吗?我将如何进行设置。

一些背景信息 example.com 正在运行 Magento,asia.example.com 将成为现在的登录页面。

谢谢

更新:我的主机说我应该在 Magento 上安装这个 https://github.com/maxmind/GeoIP2-php... 我该怎么做?

评论更新:

# Redirect multiple countries to a single page
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(VN|SG|CN|MY|JP|KP|KR)$
RewriteRule ^(.*)$ asia.example.com$1 [R,L]

【问题讨论】:

  • 请出示来自.htaccess的重定向代码
  • # 将多个国家重定向到一个页面 RewriteEngine on RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(VN|SG|CN|MY|JP|KP|KR)$ RewriteRule ^(.*)$ @ 987654322@ [R,L]

标签: .htaccess magento redirect geolocation magento-1.7


【解决方案1】:

通常 Magento 以选择字段的形式提供存储切换器,请参阅它在 demo.magentocommerce.com 上的工作。使用的主题可能会改变它的显示方式,它可以是一个链接或按钮,但原理是一样的,store cookie 是用存储代码作为它的值编写的。我们可以直接在.htaccess 中进行测试,如果存在则避免使用 GeoIP。

# Redirect multiple countries to a single page
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(VN|SG|CN|MY|JP|KP|KR)$

# New cookie condition goes here
# ! means true when it doesn't match
# \b means word boundary
RewriteCond %{HTTP_COOKIE} !\bstore=default\b

RewriteRule ^(.*)$ asia.example.com$1 [R,L]

必须在每个请求上传输 cookie,否则用户可能会发现自己稍后会被重定向。如果行为不端,您可能必须将 cookie 域设置为 .example.com(注意前导句点)。您可以在 Magento 的管理员中的 System > Configuration > Web > Session Cookie Management 下执行此操作。 这允许 cookie 由 asia.example.com 写入并由 example.com 读取,反之亦然。 p>

如果你想创建一个链接而不是商店切换器然后使用Mage::getUrl,它会生成一个带有___store查询参数的URL:

<?php
    $url = Mage::getUrl('', array(
        '_store' => 'default',
        '_store_to_url' => true
    ));
?>
<a href="<?php echo $url ?>"><?php echo $this->__('International Store') ?></a>

【讨论】:

  • 非常感谢,但这是另一个问题,上面提到的 asia.example.com 是一个登录页面 :( 它现在不运行 magento,但在被重定向后我需要用户离开以返回如果需要,原始域 example.com。
  • 那么登陆页面需要一个指向//example.com/?___store=default的链接,这是你可以逃脱的最低限度。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-06-18
  • 2012-07-27
  • 2020-11-12
  • 2011-12-09
  • 2016-07-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多