js方法:
var urlqr = location.href;
urlqr = urlqr.replace(/iphoneF_/, "pc")这里写正则替换页面地址
if(IsPC()) window.location.replace(urlqr);//PC端访问就跳转到PC页面
else window.location.replace(urlqr);//否则跳转移动页面
//判断是否pc端访问
function IsPC() {
var userAgentInfo = navigator.userAgent;
var Agents = ["Android", "iPhone",
"SymbianOS", "Windows Phone",
"iPad", "iPod"];
var flag = true;
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false;
break;
}
}
return flag;
}
PHP:判断web端访问还是移动端访问
只需匹配$_SERVER['HTTP_USER_AGENT']变量
if (stripos($_SERVER['HTTP_USER_AGENT'],'windows')) {
$isWeb = '';
} else {
$isiPhone = '';
}