菜心哥 发表于 2021-10-7 20:48:28

discuz手机版去除网址链接后缀尾巴&mobile=2

刚开始用DZ搭建好的网站,用手机端分享的内容在电脑上打开时会跳出一个二维码,提醒用手机扫码查看,这样的体验是不好的,如下图:
https://cgb.lucaixing.com/wp-content/uploads/2021/10/QQ图片20211007201944.png
后来在百度找到了一种方法是通过注释或删除./source/class/discuz/discuz_application.php 第755行的方法解决:
https://cgb.lucaixing.com/wp-content/uploads/2021/10/lcx截图20211007202926.png
这样是解决了链接打开的体验问题,但最近发现链接还是会有类似......&mobile=2这样的后缀尾巴,会有一种不规范的感觉,今天再次上网搜到了一种更好的方法,上面的文件可以不用改动,恢复原样,按下面的方法就行了,没有后缀的感觉就是清爽了许多。
第一步:找到文件/source/class/helper/helper_mobile.php中:$content = preg_replace_callback("/href=\"(\w+\.php)(.*?)\"/", array(__CLASS__, 'mobileoutput_callback_mobilereplace_12'), $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 = $str_arr.'&mobile='.IN_MOBILE;
                              $string = implode('#', $str_arr);
                        }
                }
      }删除或者注释掉即可。小伙伴们可以在手机端分享本文到电脑端打开看看效果,如果也遇到这样的问题就赶快动手吧!

yizhimei 发表于 2021-10-7 22:26:06

{:2_28:}{:2_28:}{:2_28:}{:2_28:}{:2_28:}{:2_28:}
页: [1]
查看完整版本: discuz手机版去除网址链接后缀尾巴&mobile=2