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 協議》,轉載必須註明作者和本文連結