2014-09-21 41 views
0

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

这是可能的还是我必须使用客户端重定向,我将如何去设置它。

一些背景信息example.com正在运行magento,asia.example.com将成为目前的着陆页。

感谢

更新:我的主人说我应该安装此https://github.com/maxmind/GeoIP2-php上Magento的......我该怎么做?从评论

更新:

# 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] 
+0

请从'.htaccess'显示您重定向代码 – clockworkgeek 2014-09-22 20:31:17

+0

#将多个国家重定向到单个页面 RewriteEngine on RewriteCond%{ENV:GEOIP_COUNTRY_CODE} ^(VN | SG | CN | MY | JP | KP | KR)$ RewriteRule ^(。*)$ http:// asia .example.com $ 1 [R,L] – Sean 2014-09-22 22:16:20

回答

0

通常的Magento提供了一个选择栏的形式储存开关,看它工作demo.magentocommerce.com。正在使用的主题可能会改变显示方式,它可能是链接或按钮,但原理相同,因此cookie的商店代码将写入一个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的管理员的系统>配置> Web>会话Cookie管理中执行此操作。这使得cookie可以被asia.example.com写入并被example.com读取,反之亦然。

如果你想要做一个链接,而不是在商店切换那么以这种方式使用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> 
+0

非常感谢,但这里有另一个问题,上面提到的asia.example.com是一个登陆页面:(它不运行法师nto现在但我需要重新定向后返回到原来的域example.com需要的用户。 – Sean 2014-09-23 07:53:30

+0

然后登陆页面需要一个链接到'//example.com /?___ store = default',这是你可以逃脱的最低限度。 – clockworkgeek 2014-09-23 10:05:40