您现在的位置: 365建站网 > 365文章 > Discuz! X3.4 SEO手机伪静态设置原理和方法

Discuz! X3.4 SEO手机伪静态设置原理和方法

文章来源:365jz.com     点击数:1693    更新时间:2020-07-18 12:06   参与评论

Discuz! X3.4 SEO手机伪静态设置原理和方法:

实现Discuz手机触屏版伪静态,统一PC端和手机触屏版的访问地址,有利于手机版的SEO优化,方便搜索引擎移动端适配,提升站点移动端收录量(移动端搜素已超越PC端搜索)实现Discuz手机触屏版伪静态,统一PC端和手机触屏版的访问地址,有利于手机版的SEO优化,方便搜索引擎移动端适配,提升站点移动端收录量(移动端搜素已超越PC端搜索)

通过查找,发现电脑版设置伪静态的方法

1,通过后台设置seo选项

image.png

规则如下:

</>code

  1. [ISAPI_Rewrite]
  2. # 3600 = 1 hour
  3. CacheClockRate 3600
  4. RepeatLimit 32
  5. # Protect httpd.ini and httpd.parse.errors files
  6. # from accessing through HTTP
  7. RewriteRule ^(.*)/topic-(.+)\.html(\?(.*))*$ $1/portal\.php\?mod=topic&topic=$2&$4
  8. RewriteRule ^(.*)/article-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/portal\.php\?mod=view&aid=$2&page=$3&$5
  9. RewriteRule ^(.*)/forum-(\w+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=forumdisplay&fid=$2&page=$3&$5
  10. RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&$6
  11. RewriteRule ^(.*)/group-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=group&fid=$2&page=$3&$5
  12. RewriteRule ^(.*)/space-(username|uid)-(.+)\.html(\?(.*))*$ $1/home\.php\?mod=space&$2=$3&$5
  13. RewriteRule ^(.*)/blog-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/home\.php\?mod=space&uid=$2&do=blog&id=$3&$5
  14. RewriteRule ^(.*)/(fid|tid)-([0-9]+)\.html(\?(.*))*$ $1/archiver/index\.php\?action=$2&value=$3&$5


然后找到source/function/function_core.php中的函数

</>code

  1. function rewriteoutput($type, $returntype, $host) {
  2. global $_G;
  3. $fextra = '';
  4. if($type == 'forum_forumdisplay') {
  5. list(,,, $fid, $page, $extra) = func_get_args();
  6. $r = array(
  7. '{fid}' => empty($_G['setting']['forumkeys'][$fid]) ? $fid : $_G['setting']['forumkeys'][$fid],
  8. '{page}' => $page ? $page : 1,
  9. );
  10. } elseif($type == 'forum_viewthread') {
  11. list(,,, $tid, $page, $prevpage, $extra) = func_get_args();
  12. $r = array(
  13. '{tid}' => $tid,
  14. '{page}' => $page ? $page : 1,
  15. '{prevpage}' => $prevpage && !IS_ROBOT ? $prevpage : 1,
  16. );
  17. } elseif($type == 'home_space') {
  18. list(,,, $uid, $username, $extra) = func_get_args();
  19. $_G['setting']['rewritecompatible'] && $username = rawurlencode($username);
  20. $r = array(
  21. '{user}' => $uid ? 'uid' : 'username',
  22. '{value}' => $uid ? $uid : $username,
  23. );
  24. } elseif($type == 'home_blog') {
  25. list(,,, $uid, $blogid, $extra) = func_get_args();
  26. $r = array(
  27. '{uid}' => $uid,
  28. '{blogid}' => $blogid,
  29. );
  30. } elseif($type == 'group_group') {
  31. list(,,, $fid, $page, $extra) = func_get_args();
  32. $r = array(
  33. '{fid}' => $fid,
  34. '{page}' => $page ? $page : 1,
  35. );
  36. } elseif($type == 'portal_topic') {
  37. list(,,, $name, $extra) = func_get_args();
  38. $r = array(
  39. '{name}' => $name,
  40. );
  41. } elseif($type == 'portal_article') {
  42. list(,,, $id, $page, $extra) = func_get_args();
  43. $r = array(
  44. '{id}' => $id,
  45. '{page}' => $page ? $page : 1,
  46. );
  47. } elseif($type == 'forum_archiver') {
  48. list(,, $action, $value, $page, $extra) = func_get_args();
  49. $host = '';
  50. $r = array(
  51. '{action}' => $action,
  52. '{value}' => $value,
  53. );
  54. if($page) {
  55. $fextra = '?page='.$page;
  56. }
  57. } elseif($type == 'plugin') {
  58. list(,, $pluginid, $module,, $param, $extra) = func_get_args();
  59. $host = '';
  60. $r = array(
  61. '{pluginid}' => $pluginid,
  62. '{module}' => $module,
  63. );
  64. if($param) {
  65. $fextra = '?'.$param;
  66. }
  67. }
  68. $href = str_replace(array_keys($r), $r, $_G['setting']['rewriterule'][$type]).$fextra;
  69. if(!$returntype) {
  70. return '<a href="'.$host.$href.'"'.(!empty($extra) ? stripslashes($extra) : '').'>';
  71. } else {
  72. return $host.$href;
  73. }
  74. }

这是实现电脑版伪静态的处理函数


在移动版中,找到source\class\helper\helper_mobile.php中的函数 mobilereplace,修改成如下所示:

</>code

  1. public static function mobilereplace($file, $replace) {
  2. if(strpos($replace, 'mobile=') === false) {
  3. if(strpos($replace, '?') === false) {
  4. $replace = 'href="'.$file.$replace.'?mobile='.IN_MOBILE.'"';
  5. } else {
  6. $replace = 'href="'.$file.$replace.'&amp;mobile='.IN_MOBILE.'"';
  7. //$replace=str_replace('&amp;mobile=2','',$replace);
  8. $replace=mbrewriteoutput($replace);
  9. }
  10. return $replace;
  11. } else {
  12. return 'href="'.$file.$replace.'"';
  13. }
  14. }

然后在source/function/function_core.php中增加函数

</>code

  1. function mbrewriteoutput($eurl) {
  2. if(strstr($eurl,"forum.php?mod=forumdisplay&amp;fid=")){
  3.         $eurl=str_replace('&amp;mobile=2','',$eurl);
  4. $fidarr=explode("fid=",$eurl);
  5. $fid=$fidarr[1];
  6. $fid=str_replace('"','',$fid);
  7. $eurl=str_replace('forum.php?mod=forumdisplay&amp;fid='.$fid,'forum-'.$fid.'-1.html',$eurl);
  8. $eurl=str_replace('forum.php?mod=forumdisplay&fid='.$fid,'forum-'.$fid.'-1.html',$eurl);
  9. return $eurl;
  10. }elseif(strstr($eurl,"forum.php?mod=viewthread&amp;tid=")){
  11. $eurl=str_replace('&amp;extra=page%3D1&amp;mobile=2','',$eurl);
  12. $tidarr=explode("tid=",$eurl);
  13. $tid=$tidarr[1];
  14. $tid=str_replace('"','',$tid);
  15. $eurl=str_replace('forum.php?mod=viewthread&amp;tid='.$tid,'thread-'.$tid.'-1-1.html',$eurl);
  16. $eurl=str_replace('forum.php?mod=viewthread&amp;tid='.$tid,'thread-'.$tid.'-1-1.html',$eurl);
  17. return $eurl;
  18. }elseif(strstr($eurl,"forum.php?forumlist=1&amp;mobile=2")){
  19. $eurl=str_replace('forum.php?forumlist=1&amp;mobile=2','https://bbs.365jz.com/',$eurl);
  20. return $eurl;
  21. }
  22. return $eurl;
  23. }

这样就可以实现手机伪静态

如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛

发表评论 (1693人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
昵称:
最新评论
2020年10月29日 17:12suchang888

你好 这个是IIS 的吧
Nginx应该怎么写

------分隔线----------------------------

快速入口

· 365软件
· 杰创官网
· 建站工具
· 网站大全

其它栏目

· 建站教程
· 365学习

业务咨询

· 技术支持
· 服务时间:9:00-18:00
365建站网二维码

Powered by 365建站网 RSS地图 HTML地图

copyright © 2013-2024 版权所有 鄂ICP备17013400号