如何使用.htcaccess将仅针对移动浏览器的特定页面重写/重定向到外部URL?

问题描述:

我不知道是否有可能在.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 

我使用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

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

$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);