2013-05-28 34 views
1

我不知道是否有可能在.htcaccess文件中編碼,並使其重定向/重寫到外部URL。這是一個Joomla網站。如何使用.htcaccess將僅針對移動瀏覽器的特定頁面重寫/重定向到外部URL?

我想要的是與移動設備遊人如手機或平板電腦應該當他們訪問此頁面重定向: http://www.axima.se/index.php/nytt-a-begagnat/sok-begagnade-maskiner

這是我希望他們能夠被引導到網址: http://m.dealers.mascus.com/Axima

我發現這個線程,並用它爲靈感,嘗試了一些代碼組合,但我不是能夠把正確的代碼一起 Redirecting only a specific page request for mobile users using htaccess

這段代碼是從舊約她的線程(一個WordPress站點)和林不知道,以保持並在那裏把我的代碼:

# BEGIN Mobile redirect for the video 
<IfModule mod_rewrite.c> 
    RewriteEngine On 
    # stuff to let through (ignore) 
    RewriteRule ^mobile/ - [L] 
    # redirect /video.html to /mobile/index.html for mobile browsers 
    RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC] 
    RewriteRule ^video\.html$ /mobile/index.html [L,R=302] 
</IfModule> 
# END Mobile redirect 

回答

0

我使用http://mobiledetect.net該功能

在MyTemplate的頂部/ index.php文件:

include 'pathtolibrary/Mobile_Detect.php'; 
$detect = new Mobile_Detect(); 
$mob = JURI::base()."index.php?option=com_yourcomponent&view=mobile"; 
if ($detect->isMobile()) JFactory::getApplication()->redirect($mob, $error, 'error'); 

所以你不需要使用htaccess。 你可以看到它在我的網站www.menagenet.co.il

+0

的Joomla已經具有檢測移動的能力。爲什麼要包含並維護另一個額外的類 –

+0

好吧,聽起來很合理,你可以提供關於如何使用joomla的代碼做到這一點的線索嗎? – amitgur

+0

看到我的答案,讓我知道它是如何爲你工作的。 –

1
$browser = JBrowser::getInstance(); 
if ($browser->isMobile() === true) 
    echo "<p>Mobile website</p>"; 
else 
    echo "<p>Standard website</p>"; 

echo "<p>More info on the user agent: </p>"; var_dump($browser); 
相關問題