Discuz! X3.4 SEO手機偽靜態(tài)設(shè)置原理和方法:
實現(xiàn)Discuz手機觸屏版?zhèn)戊o態(tài),統(tǒng)一PC端和手機觸屏版的訪問地址,有利于手機版的SEO優(yōu)化,方便搜索引擎移動端適配,提升站點移動端收錄量(移動端搜素已超越PC端搜索)實現(xiàn)Discuz手機觸屏版?zhèn)戊o態(tài),統(tǒng)一PC端和手機觸屏版的訪問地址,有利于手機版的SEO優(yōu)化,方便搜索引擎移動端適配,提升站點移動端收錄量(移動端搜素已超越PC端搜索)
通過查找,發(fā)現(xiàn)電腦版設(shè)置偽靜態(tài)的方法
1,通過后臺設(shè)置seo選項
規(guī)則如下:
[ISAPI_Rewrite] # 3600 = 1 hour CacheClockRate 3600 RepeatLimit 32 # Protect httpd.ini and httpd.parse.errors files # from accessing through HTTP RewriteRule ^(.*)/topic-(.+)\.html(\?(.*))*$ $1/portal\.php\?mod=topic&topic=$2&$4 RewriteRule ^(.*)/article-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/portal\.php\?mod=view&aid=$2&page=$3&$5 RewriteRule ^(.*)/forum-(\w+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=forumdisplay&fid=$2&page=$3&$5 RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&$6 RewriteRule ^(.*)/group-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=group&fid=$2&page=$3&$5 RewriteRule ^(.*)/space-(username|uid)-(.+)\.html(\?(.*))*$ $1/home\.php\?mod=space&$2=$3&$5 RewriteRule ^(.*)/blog-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/home\.php\?mod=space&uid=$2&do=blog&id=$3&$5 RewriteRule ^(.*)/(fid|tid)-([0-9]+)\.html(\?(.*))*$ $1/archiver/index\.php\?action=$2&value=$3&$5
然后找到source/function/function_core.php中的函數(shù)
function rewriteoutput($type, $returntype, $host) { global $_G; $fextra = ''; if($type == 'forum_forumdisplay') { list(,,, $fid, $page, $extra) = func_get_args(); $r = array( '{fid}' => empty($_G['setting']['forumkeys'][$fid]) ? $fid : $_G['setting']['forumkeys'][$fid], '{page}' => $page ? $page : 1, ); } elseif($type == 'forum_viewthread') { list(,,, $tid, $page, $prevpage, $extra) = func_get_args(); $r = array( '{tid}' => $tid, '{page}' => $page ? $page : 1, '{prevpage}' => $prevpage && !IS_ROBOT ? $prevpage : 1, ); } elseif($type == 'home_space') { list(,,, $uid, $username, $extra) = func_get_args(); $_G['setting']['rewritecompatible'] && $username = rawurlencode($username); $r = array( '{user}' => $uid ? 'uid' : 'username', '{value}' => $uid ? $uid : $username, ); } elseif($type == 'home_blog') { list(,,, $uid, $blogid, $extra) = func_get_args(); $r = array( '{uid}' => $uid, '{blogid}' => $blogid, ); } elseif($type == 'group_group') { list(,,, $fid, $page, $extra) = func_get_args(); $r = array( '{fid}' => $fid, '{page}' => $page ? $page : 1, ); } elseif($type == 'portal_topic') { list(,,, $name, $extra) = func_get_args(); $r = array( '{name}' => $name, ); } elseif($type == 'portal_article') { list(,,, $id, $page, $extra) = func_get_args(); $r = array( '{id}' => $id, '{page}' => $page ? $page : 1, ); } elseif($type == 'forum_archiver') { list(,, $action, $value, $page, $extra) = func_get_args(); $host = ''; $r = array( '{action}' => $action, '{value}' => $value, ); if($page) { $fextra = '?page='.$page; } } elseif($type == 'plugin') { list(,, $pluginid, $module,, $param, $extra) = func_get_args(); $host = ''; $r = array( '{pluginid}' => $pluginid, '{module}' => $module, ); if($param) { $fextra = '?'.$param; } } $href = str_replace(array_keys($r), $r, $_G['setting']['rewriterule'][$type]).$fextra; if(!$returntype) { return '<a href="'.$host.$href.'"'.(!empty($extra) ? stripslashes($extra) : '').'>'; } else { return $host.$href; } }
這是實現(xiàn)電腦版?zhèn)戊o態(tài)的處理函數(shù)
在移動版中,找到source\class\helper\helper_mobile.php中的函數(shù) mobilereplace,修改成如下所示:
public static function mobilereplace($file, $replace) { if(strpos($replace, 'mobile=') === false) { if(strpos($replace, '?') === false) { $replace = 'href="'.$file.$replace.'?mobile='.IN_MOBILE.'"'; } else { $replace = 'href="'.$file.$replace.'&mobile='.IN_MOBILE.'"'; //$replace=str_replace('&mobile=2','',$replace); $replace=mbrewriteoutput($replace); } return $replace; } else { return 'href="'.$file.$replace.'"'; } }
然后在source/function/function_core.php中增加函數(shù)
function mbrewriteoutput($eurl) { if(strstr($eurl,"forum.php?mod=forumdisplay&fid=")){ $eurl=str_replace('&mobile=2','',$eurl); $fidarr=explode("fid=",$eurl); $fid=$fidarr[1]; $fid=str_replace('"','',$fid); $eurl=str_replace('forum.php?mod=forumdisplay&fid='.$fid,'forum-'.$fid.'-1.html',$eurl); $eurl=str_replace('forum.php?mod=forumdisplay&fid='.$fid,'forum-'.$fid.'-1.html',$eurl); return $eurl; }elseif(strstr($eurl,"forum.php?mod=viewthread&tid=")){ $eurl=str_replace('&extra=page%3D1&mobile=2','',$eurl); $tidarr=explode("tid=",$eurl); $tid=$tidarr[1]; $tid=str_replace('"','',$tid); $eurl=str_replace('forum.php?mod=viewthread&tid='.$tid,'thread-'.$tid.'-1-1.html',$eurl); $eurl=str_replace('forum.php?mod=viewthread&tid='.$tid,'thread-'.$tid.'-1-1.html',$eurl); return $eurl; }elseif(strstr($eurl,"forum.php?forumlist=1&mobile=2")){ $eurl=str_replace('forum.php?forumlist=1&mobile=2','https://bbs.365jz.com/',$eurl); return $eurl; } return $eurl; }
這樣就可以實現(xiàn)手機偽靜態(tài)
如對本文有疑問,請?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會為你解答??! 點擊進入論壇