移动重定向循环

时间:2013-12-26 20:02:55

标签: php wordpress mobile

我希望将移动用户重定向到我的WP网站上的特定页面。我试图使用这个脚本,但它导致无限循环。移动页面可以位于同一个域中,还是必须为移动页面创建子域?

谢谢!

function is_mobile(){
    $regex_match="/(nokia|iphone|android|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|";
    $regex_match.="htc|dopod|blazer|netfront|helio|hos in|huawei|novarra|CoolPad|webos|techfaith|palmsour ce|";
    $regex_match.="blackberry|alcatel|amoi|ktouch|nexi an|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|ma ui|";  
    $regex_match.="symbian|smartphone|midp|wap|phone|w indows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|";
    $regex_match.="jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mob i|opera\*mini|320x320|240x320|176x220";
    $regex_match.=")/i";    

    return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT']));
}

switch($_GET['mode'])
{
case 'mobile':
    $mode = "mobile";
    break;
case 'desktop':
    $mode = "desktop";
    break;
default:
    $mode = is_mobile() ? "mobile" : "desktop";
    break;
}

if ($mode == "mobile")
{
    header ("Location: http://example.com/mobile");
    return;

1 个答案:

答案 0 :(得分:0)

在发布您当前不在移动页面上的位置标题之前添加一项检查(例如,通过选中$_SERVER['REQUEST_URI']或通过您在移动页面上设置的某个变量),或者不包含此重定向你在移动页面上的脚本。

相关问题