【问题标题】:How to redirect mobile users to mobile version of my site? [duplicate]如何将移动用户重定向到我的网站的移动版本? [复制]
【发布时间】:2013-06-20 23:53:21
【问题描述】:

我有一个网站 www.domain.com,我设计了一个新的移动版本 m.domain.com。但是如何检测移动设备并将其从 www.domain.com 重定向到 m.domain.com?

【问题讨论】:

  • 链接到副本会很棒。我们是在谈论 2009 年的帖子吗?还是 2010 年?

标签: php javascript jquery css html


【解决方案1】:

我刚刚在谷歌搜索,这是第一个结果:

http://mobiledetect.net/

include 'Mobile_Detect.php';
$detect = new Mobile_Detect();

// Check for any mobile device.
if ($detect->isMobile())

// Check for any tablet.
if($detect->isTablet())

// 3. Check for any mobile device, excluding tablets.
if ($detect->isMobile() && !$detect->isTablet())

【讨论】:

    【解决方案2】:

    使用此代码检测移动设备,然后将其重定向:-

    <script>
    if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
    window.location = "m.domain.com";
    }
    </script>
    

    test() 方法已用于测试字符串中的匹配项,如果找到匹配项,则会进行重定向。在页面顶部添加此代码。

    【讨论】:

    • @vivek 以及如何重定向到移动版本...如果你能给我完整的代码会更好
    • @Amarjeet 查看我的更新答案。它只是几行解决方案。
    • @vivek 感谢您的帮助。但是您能告诉我在此代码中包含的位置吗?以及是否需要在此代码中包含其他任何内容。
    • 您必须在
    • 您不应使用 JavaScript 重定向,因为您无法设置正确的响应标头(301、302),这对 SEO 不利。按照下面 Jari 的说明使用 PHP。
    猜你喜欢
    • 2014-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-10
    • 1970-01-01
    • 2013-06-04
    • 1970-01-01
    相关资源
    最近更新 更多