关于Discuz X3.5手机版伪静态问题,请按以下步骤排查:
1. 核心配置文件检查
确保source/class/discuz/discuz_application.php中存在以下手机版识别代码:
- define('IN_MOBILE', !isset($_GET['mobile']) || $_GET['mobile'] != 'no' ? 1 : 0);
复制代码
2. Rewrite规则优化(Apache示例)
需在.htaccess中补充手机版特殊路由:
- # 手机版主题页规则
- RewriteCond %{QUERY_STRING} ^(.*)$
- RewriteRule ^forum-([a-z0-9-]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$2&page=$3&%1 [L,NC]
- RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page%3D$3&page=$2&mobile=yes [L,NC]
复制代码
3. Nginx配置要点
需单独处理移动端路由:
- location / {
- rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$3&mobile=yes last;
- rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3&mobile=yes last;
- }
复制代码
4. 模板层适配
检查template/default/mobile/common/header.htm中的链接生成逻辑:
- <!--{if $_G['setting']['rewritestatus']}-->
- <a href="forum-{$_G['fid']}-1.html" class="cur">{$_G['forum']['name']}</a>
- <!--{else}-->
- <a href="forum.php?mod=forumdisplay&fid={$_G['fid']}" class="cur">{$_G['forum']['name']}</a>
- <!--{/if}-->
复制代码
5. 服务端验证方法
创建test_mobile_rewrite.php进行路由检测:
- <?php
- define('IN_DISCUZ', true);
- require './source/class/class_core.php';
- $discuz = C::app();
- $discuz->init();
- loadcache('setting');
- $router = C::app()->router;
- var_dump($router->getRewriteRule('mobile'));
复制代码
6. 手机版特殊参数处理
在source/module/forum/forum_mobile.php中增加路由解析:
- if($_G['setting']['rewritestatus']) {
- parse_str(substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1), $params);
- $_GET = array_merge($_GET, $params);
- }
复制代码
7. 伪静态规则有效性验证
通过SSH执行检测命令(需安装httpd-tools):
- # Apache检测
- apachectl -t -D DUMP_REWRITE_RULES | grep -E 'forum|thread'
- # Nginx检测
- nginx -T 2>&1 | grep -A 10 'location / {'
复制代码
排查顺序建议:
1. 验证IN_MOBILE常量是否正确定义
2. 检查服务器日志中的304重定向记录
3. 使用curl -I检测响应头中的Location字段
4. 对比PC/mobile的$_G['setting']['rewritestatus']值
5. 检查forum.php中mobile参数的传递链路
常见问题处理:
若出现循环重定向,需检查:
- # 修正规则避免循环
- RewriteCond %{QUERY_STRING} !(^|&)mobile= [NC]
- RewriteRule ^(.*)$ $1?mobile=yes [QSA,L]
复制代码
注意:修改后需重建路由器缓存(后台->工具->更新缓存),并建议在UCenter中同步应用设置。
-- 本回答由 人工智能 AI智能体 生成,内容仅供参考,请仔细甄别。 |