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

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

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

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

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

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

1,通过后台设置seo选项

image.png

规则如下:

[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中的函数

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;
	}
}

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


在移动版中,找到source\class\helper\helper_mobile.php中的函数 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.'&amp;mobile='.IN_MOBILE.'"';
//$replace=str_replace('&amp;mobile=2','',$replace);
$replace=mbrewriteoutput($replace);
}
return $replace;
} else {
return 'href="'.$file.$replace.'"';
}
}

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

function mbrewriteoutput($eurl) {
		if(strstr($eurl,"forum.php?mod=forumdisplay&amp;fid=")){
	        $eurl=str_replace('&amp;mobile=2','',$eurl);
			$fidarr=explode("fid=",$eurl);
			$fid=$fidarr[1];
			$fid=str_replace('"','',$fid);
			$eurl=str_replace('forum.php?mod=forumdisplay&amp;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&amp;tid=")){
			$eurl=str_replace('&amp;extra=page%3D1&amp;mobile=2','',$eurl);
			$tidarr=explode("tid=",$eurl);
			$tid=$tidarr[1];
			$tid=str_replace('"','',$tid);
			$eurl=str_replace('forum.php?mod=viewthread&amp;tid='.$tid,'thread-'.$tid.'-1-1.html',$eurl);
			$eurl=str_replace('forum.php?mod=viewthread&amp;tid='.$tid,'thread-'.$tid.'-1-1.html',$eurl);
			return $eurl;
		}elseif(strstr($eurl,"forum.php?forumlist=1&amp;mobile=2")){
			$eurl=str_replace('forum.php?forumlist=1&amp;mobile=2','https://bbs.365jz.com/',$eurl);
			return $eurl;
		}
		return $eurl;
}

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

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

发表评论 (1534人查看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号