簡體   English   中英

重定向在Opera中有效,但在fennec和其他移動瀏覽器中無效嗎?

[英]Redirection is working in opera but not in fennec and other mobile browsers?

我有一個移動網站,並且正在將移動用戶從主網站重定向到移動網站。 但是我在移動網站上也提供了一些選擇,如果某些移動用戶想要訪問主網站,他可以。 為了解決這個問題,我在主網站上編寫了此代碼

if (is_mobile()== true) //if user is browsing from mobile
{

    $main_website_url= 'http://localhost/www/redsignal/';   // main website URL

    $mobilesite_url = 'http://localhost/www/redsignal-mobile/';  //mobile website URL

    $mobilesite_url_length = strlen($mobilesite_url);

    $referring_path_url = substr($_SERVER['HTTP_REFERER'], 0 , $mobilesite_url_length);

    if ($referring_path_url == $mobilesite_url) //This if condition checks that if the mobile user is coming from my mobile website or not
    {
        header("Location:".$main_website_url);  // if he is coming from mobile he will be redirected to main website                
    }
    else
    {
        header("Location:".$mobilesite_url); // if not than he will be redirected to mobile website     
    }


}

您需要使用另一個變量來區分是否要在單擊移動站點中的訪問原始站點時強制顯示原始站點。 為此,您可以傳遞GET變量,例如

http:// localhost / www / redsignal /?force_show_original = 1

然后在您的代碼中更改此

if (is_mobile()== true)

if (is_mobile()== true || $GET["force_show_original"] == true)

讓我知道它是否有效

更新

使用以下代碼重定向網站

if (is_mobile()== true || $GET["force_show_original"] == false) {
       //redirect to mobile site
}
else if(is_mobile()== true || $GET["force_show_original"] == true) {
       // redirect to original site
}
else {
       // redirect to original site
}

如果標題不起作用,則可以使用javascript進行重定向,例如

echo "<script type='text/javascript'> document.location.href='$main_website_url'</script> ";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM