《关于我折腾某CMS手机端的这件事》

前言

由于公司的老站点网站没有做自适应且后台用的某cms的后台 它自带/m 手机端  这里就要折腾下这个手机端的处理问题了  由于系统用的win iis环境 只能用url重写了

www跳m

直接上代码   pc所有站点模板顶部<head></head>内添加
(保证每个pc的通用模板都有个副本都以_m结尾如article_article_m.htm)
首页:

<meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobileurl/}/index.php">
<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex')!=-1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent)||(/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="{dede:global.cfg_mobileurl/}/index.php";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>

列表|封面模板:

<meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobileurl/}/list.php?tid={dede:field.id/}">
<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else
{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent)||(/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="{dede:global.cfg_mobileurl/}/list.php?tid={dede:field.id/}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>

文章详情模板:

<meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobileurl/}/view.php?aid={dede:field.id/}">
<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else
{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent)||(/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="{dede:global.cfg_mobileurl/}/view.php?aid={dede:field.id/}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>

伪静态优化:

{dede:global.cfg_mobileurl/}/list.php?tid={dede:field.id/} 替换 为/m/list/{dede:field.id/}
{dede:global.cfg_mobileurl/}/view.php?aid={dede:field.id/} 替换 为/m/article/{dede:field.id/}

统合优化:将PC版页面指向移动版页面 将移动版页面指向PC版页面有利于搜索引擎 对不同设备的用户提供不同类型的页面
PC版本head前添加:

<link media="only screen and (max-width:640px)" href="http://m.xxx.com" >

移动版本head前添加:

<link href="http://wwww.xxx.com" >

不嫌麻烦最好每个 二级页面都分别加上对应的链接

URL重写

 <rewrite>
<rules>
<clear />
<rule name="listpa" enabled="true" stopProcessing="true">
<match url="^m/list/list_([0-9]*)_([0-9]*).html$" />
<action type="Rewrite" url="/m/list.php?tid={R:1}&amp;PageNo={R:2}" />
</rule>
<rule name="m_list">
<match url="^m/list/(\d*)\.html$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="/m/list.php?tid={R:1}" appendQueryString="false" />
</rule>
<rule name="m_article" enabled="true">
<match url="^m/article/([0-9]+)\.html$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="/m/view.php?aid={R:1}" appendQueryString="false" />
</rule>
<rule name="m" enabled="true" stopProcessing="false">
<match url="^(index\.html|\s*)$" negate="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^m\.pc\.com$" />
</conditions>
<action type="Rewrite" url="/m" appendQueryString="false" />
</rule>
</rules>
</rewrite>

复制添加到web.config里 <system.webServer>中间</system.webServer>

补充

手机端的list分页可能会出问题 修改下代码:
打开 /include/arc.listview.class.php 找到

$geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
$purl .= '?'.$geturl;

修改为:

if($cfg_rewrite == 'Y')
{
$purl = "";
}
else
{
$geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
$purl .= '?'.$geturl;
}

继续找到

$plist = str_replace('.php?tid=', '-', $plist);

在它的上面加入

$tnamerule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],$this->Fields['defaultname'],$this->Fields['namerule2']);
$tnamerule = preg_replace("/^(.*)\//", '', $tnamerule);
$plist = preg_replace("/PageNo=(\d+)/i",str_replace("{page}","\\1",$tnamerule),$plist);

内容页的上一篇下一篇修改
打开 /include/arc.archives.class.php 找到
$mlink = 'view.php?aid='.$preRow['id']; 改成 $mlink = $preRow['id'].'.html';
 

最后

使用这种www和m站点 有好处也有坏处
好处:能多开权重 一个被k 另一个还能顶上
坏处:麻烦 繁琐 容易被自己跟自己抢权重

点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注