2014-01-17 86 views
0

我正在使用MobileDetectBundle製作我的網站的移動版本。Symfony2 MobileDetectBundle重定向不起作用

我想重新定向到像使用示例中的移動網站。我的config.yml是自述文件中的內容的複製/粘貼。

mobile_detect: 
    redirect: 
     mobile: 
      is_enabled: true 
      host: http://mobilesite.local 
      status_code: 301 
      action: redirect 
     tablet: ~ 
    switch_device_view: ~ 

但是當我點擊http://website.local什麼也沒有發生。我正在使用User Agent Switcher Firefox extension作爲移動瀏覽器顯示。

該捆綁看起來配置得很好,因爲當我使用is_mobile()枝條助手時,它將我檢測爲手機。

有什麼想法?提前致謝。

Guillaume

回答

2

感謝erlangb我找到了答案,配置移動環境。切換瀏覽器的用戶代理是不夠的。

MobileDetectBundle創建一個名爲device_view的cookie,因此您必須刪除此cookie才能切換並顯示爲移動設備。

+0

謝謝,我本來可以花幾個小時弄清楚這個 – JuCachalot

+0

謝謝,這工作!對於開發,您還可以在config.yml中設置以下密鑰:'cookie_expire_datetime_modifier:「+1秒」 – baris1892

0

你是否正確地遵循了指南?

從自述

「現在,當你點擊到http://site.com您將被重定向到http://m.site.com此時如果http://m.site.com被配置爲指向您的項目你會得到循環引用錯誤,爲了擺脫循環引用錯誤,我們希望當我們登陸移動網站時禁用移動重定向。「

你必須按照步驟2和MobileDetectBundle

的3
+0

問題是,在步驟1中,我沒有任何循環引用錯誤。看起來根本沒有重定向。 可以肯定,我在另一個虛擬主機上配置了http://mobilesite.local。 我也嘗試做第​​2步和第3步,但沒有更好的工作。 – moins52

+1

嘗試去這裏:https://github.com/suncat2000/MobileDetectBundle/blob/master/EventListener/RequestListener.php有聽衆檢查是否存在移動重定向。如果is_enabled = true,則函數返回false ... protected function hasMobileRedirect() { 如果(!$ this-> redirectConf ['mobile'] ['is_enabled']){ return false; } 嘗試設置爲false「is_enabled」配置或嘗試調試此事件偵聽器以檢查行爲 – erlangb

+0

我找到了答案。非常感謝。 – moins52