解决手机端和 PC 端跳转不同页面

NGINX 检测跳转#

如果是手机端和 pc 端需要跳转不同的页面,则需要在 nginx.conf 中的 location / {} 中加入如下代码:

if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry)') {
    rewrite ^.+ http://127.0.0.1:8080/mobile/$uri;
}

其中 mobile 为手机端的路径标识,可以自定义修改.

JavaScript 检测跳转#

<script>
    //H5移动版自适应跳转js
    var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mini", "mobile", "mobi", "mqqbrowser", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "symbian", "wp7", "wp8", "lg", "ucweb", "skyfire");
    var browser = navigator.userAgent.toLowerCase();
    var _tag = "{$_GET['tag']}";
    if(_tag != 'web'){
        for (var i = 0; i < mobileAgent.length; i++) {
            if (browser.indexOf(mobileAgent[i]) != -1) {
                window.location.href = 'http://www.xxx.com';
                break;
            }
        }
    }
</script>
本作品采用《CC 协议》,转载必须注明作者和本文链接
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。