Discuz触屏版链接删除尾巴(mobile=2)的方法

 

我们用来区分手机版是触屏版还是简易版等链接是通过&mobile=X来区分。所以现在基本上是&mobile=2;

那么问题就来了,带有&mobile=2的链接在PC上访问是进入misc.php?mod=mobile这个页面,有人会说这有什么关系呢?

这就得说说我们最最关心的了,搜索引擎现在也在大力发展手机方面内容,它有可能收录到带有&mobile=2的链接,那么在PC上访问到这样的链接就惨不忍睹了。

方法如下:

第一步:

找到文件/source/class/helper/helper_mobile.php中:

$content = preg_replace("/href=\"(\w+\.php)(.*?)\"/e", "mobilereplace('\\1', '\\2')", $content);

复制代码

 

将其删除或者注释掉即可;

第二步:

查找文件/source/function/function_core.php中:

function dheader($string, $replace = true, $http_response_code = 0)

复制代码

 

将其下面的:

if(defined('IN_MOBILE') && strpos($string, 'mobile') === false && $islocation) {
                if (strpos($string, '?') === false) {
                        $string = $string.'?mobile='.IN_MOBILE;
                } else {
                        if(strpos($string, '#') === false) {
                                $string = $string.'&mobile='.IN_MOBILE;
                        } else {
                                $str_arr = explode('#', $string);
                                $str_arr[0] = $str_arr[0].'&mobile='.IN_MOBILE;
                                $string = implode('#', $str_arr);
                        }
                }
        }

 

删除或者注释掉即可。

这样做之后再手机上访问和PC上访问的是同一个链接,也能正常访问手机版,需要注意的是要设置默认手机版是触屏版,相信现在没人不是这么设置。

这样修改还有一个好处就是理论上会减些轻服务器负担,提升速度虽然人难体会得到。

五月源码网 discuz教程 Discuz触屏版链接删除尾巴(mobile=2)的方法 https://www.u532.com/1188.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务