[英]how to redirect if mobile and url = specific url
我有一個基於php的網站,我想將用戶重定向到特定頁面的移動版本,但僅針對那些URL,我想保留某些URL,以使功能按當前方式工作。
我知道你可以在config.php中設置一條規則
if(!defined('_MOBILE') && !defined('_ADMIN') && $_SESSION['DV'] != 'true' && $_REQUEST['code'] == '' && $converting != 'true') {
header("Location:".$config['MOBILE_URL'].$vinf);
exit;
}
但是,如果找到了移動設備,它將在所有頁面上重定向,例如,我只想重定向(mobile && location =“ mysite / test”){// do redirect}
關於如何解決這個問題有什么建議嗎? 是否需要在每個必須進行重定向的單獨php頁面上而不是在config.php文件中設置規則?
謝謝您的幫助。
編輯:
當我注釋掉以下內容時,瀏覽器在移動設備上時不會重定向用戶:
/*
$config['GLOBAL_ENV'] = (strpos(php_sapi_name(), 'cgi')) ? 'env -i ' : NULL;
$config['MOBILE_URL'] = $config['base_url'].'/mobile';
if ($config['mobile_force_redirect'] == '1') {
$config['IPHONE'] = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
if (strpos($_SERVER['HTTP_USER_AGENT'],"iPad")) $config['IPHONE'] = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
if (stripos($ua,"android")) $config['IPHONE'] = stripos($ua,"android");
if($config['IPHONE']) {
if(!defined('_MOBILE') && !defined('_ADMIN') && $_SESSION['DV'] != 'true' && $_REQUEST['code'] == '' && $converting != 'true') {
header("Location:".$config['MOBILE_URL'].$vinf);
exit;
}
}
}*/
Mobile Detect是用於檢測移動設備(包括平板電腦)的輕量級PHP類。 它結合使用User-Agent字符串和特定的HTTP標頭來檢測移動環境。
使用它,僅顯示移動內容非常容易:
include 'Mobile_Detect.php';
$detect = new Mobile_Detect();
// Check for any mobile device.
if ($detect->isMobile() && $_SERVER['REQUEST_URI'] == "YOUR_URL_HERE"){
header("Location:".$config['MOBILE_URL'].$vinf);
exit;
}
else
// other content
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.