2014-09-21 38 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