【发布时间】:2017-05-03 04:40:42
【问题描述】:
基本上我使用的是一个非响应式网站,我有一个主站点
www.localhost.com
还有一个移动网站
www.localhost.com/mobile/
我正在使用这个 php 代码来重定向移动用户
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i";
$smartuachar = "/(ipad)/i";
//if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap'))
if(!(preg_match($smartuachar, $ua)) && ($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap'))
{
$Loaction = 'mobile/';
if (!empty($Loaction))
{
ecs_header("Location: $Loaction\n");
exit;
}
}
我面临的问题是我想将移动访问的 url 重定向到移动版本的 url
假设这个页面是从移动设备请求的
www.localhost.com/xiaomi-mi-max.html
它应该重定向到
www.localhost.com/mobile/xiaomi-mi-max.html
我有什么选择?另外,在这种情况下,最佳做法是什么? 将不胜感激。
【问题讨论】:
-
“我正在使用此 php 代码来重定向移动用户” - 您在使用此代码时遇到的具体问题是什么? (看起来它只重定向到
mobile/...您是否考虑过将当前的REQUEST_URI附加到$Loaction?)