DedeCMS Tags标签页以及列表分页伪静态如何实现

努力向前走一步,离梦想就更近一步。错过现在就等于糟蹋未来。生活就是那样,不留一丝余地,活下去似乎都需要很大的勇气。

如果不知道如何制作Tags页面,请点击《DedeCMS织梦Tags标签页制作》,前几天在《DedeCMS全站伪静态实现方法》一文中,余斗在讲全站伪静态的实现方法时,浅显的讲解了Tag标签页的伪静态实现方法,虽然能实现Tags标签的伪静态,但是列表分页还是动态的,这样并不是全部伪静态,余斗今天就详细说说DedeCMS的Tags标签页全部伪静态实现的方法:

一、Tags标签页首页伪静态

这里就是常说的tags.php页面的伪静态了,因为这个页面本身生成的就是一个伪静态的页面,只是地址是.php结尾,不少人喜欢改为.html的,那么这里只需要做好伪静态规则就可以了。

IIS6.0服务器伪静态规则为:

	
	RewriteRule ^(.*)/tags\.html $1/tags\.php
	

IIS7.0及以上服务器伪静态规则(如需扩展,请参考《IIS7、IIS8伪静态和301重定向文件web.config的规则书写》)为:

	
	 <rule name="Redirecttags" stopProcessing="true">
	            <match url="^tags.html"/>
	           <action type="Rewrite" url="tags.php"/>
	          </rule>
	

Apache服务器伪静态规则为:

	
	RewriteRule ^tags.html/tags.php
	

二、Tags标签列表页伪静态

这里即为每个关键词的相关文章列表展示页面,Dede默认的样式为/tags.php?/标签关键词,这样明显是个动态页面,我们要做修改变成一个伪静态页面,余斗就以做成/tags/关键词.html这个样式为例,作修改。

1.修改\include\taglib\tag.lib.php文件,大概在87行,把:

	
	$row['link'] = $cfg_cmsurl."/tags.php?/".urlencode($row['keyword'])."/";
	

修改为:

	
	$row['link'] = $cfg_cmsurl."/tags/".urlencode($row['keyword']).".html";
	

2.修改\include\arc.taglist.class.php文件,大概在457行,把:

	
	$purl = $this->GetCurUrl();
	$purl .= "?/".urlencode($this->Tag);
	

修改为:

	
	$purl = $cfg_cmsurl;
	$purl .= "/tags/".urlencode($this->Tag);
	

这里还有一个问题就是,首页的列表样式会生成一个/tags/keys/1.html这样的,很显然我们不需要的,这里也要做下修改,\include\arc.taglist.class.php文件,大概在507行,把:

	
	 else
	     {
	   $listdd.="<a rel="nofollow noopener noreferrer" href='".$purl."/$j.html'>".$j."</a>\r\n";
	      }
	

修改为:

	
	else
	 {
	  if($j == 1)
	   {
	       $listdd.= "<a rel="nofollow noopener noreferrer" href='".$purl.".html'>".$j."</a>\r\n";
	      }
	    else
	   $listdd.="<a rel="nofollow noopener noreferrer" href='".$purl."/$j.html'>".$j."</a>\r\n";
	  }
	

加个判断,如果是第一页就直接生成/tags/keys.html这种地址格式,就不会生成1.html这样的后缀,实现地址格式seo化。

3.IIS6.0服务器伪静态规则中写:

	
	RewriteRule ^(.*)/tags/(.*).html $1/tags\.php\?$2
	

IIS7.0及以上服务器伪静态规则中写:

	
	<rule name="Redirecttags1" stopProcessing="true">
	            <match url="^tags/(\w+).html"/>
	             <action type="Rewrite" url="tags.php?/{R:1}"/>
	          </rule>
	

Apache服务器伪静态规则中写 :

	
	RewriteRule ^tags/(.*)(?:(\?.*))*\.html$ tags\.php\?\/$1
	RewriteRule ^tags/(.*)\/(?:(\?.*))*\.html$ tags\.php\?\/$1\/
	

三、Tags标签列表页分页链接伪静态

做完前两步修改,我们会发现,tags首页和列表页实现了伪静态,但是列表页分页是/tags/关键词/2/这样的形式,而且会出现404错误,这里我们还要进一步做修改,实现像/tags/关键词/2.html这种样式。

1.修改\include\arc.taglist.class.php文件,大概在464行,把:

	
	$prepage.="<li><a rel="nofollow noopener noreferrer" href='".$purl."/$prepagenum/'>上一页</a></li>\r\n";
	$indexpage="<li><a rel="nofollow noopener noreferrer" href='".$purl."/1/'>首页</a></li>\r\n";
	

修改为(其实就是在链接后加了个后缀.html):

	
	$prepage.="<a rel="nofollow noopener noreferrer" href='".$purl."/$prepagenum.html'>上一页</a>\r\n";
	$indexpage="<a rel="nofollow noopener noreferrer" href='".$purl.".html'>首页</a>\r\n";
	

2.修改\include\arc.taglist.class.php文件,大概在473行,把:

	
	$nextpage.="<li><a rel="nofollow noopener noreferrer" href='".$purl."/$nextpagenum/'>下一页</a></li>\r\n";
	$endpage="<li><a rel="nofollow noopener noreferrer" href='".$purl."/$totalpage/'>末页</a></li>\r\n";
	

修改为(其实就是在链接后加了个后缀.html):

	
	$nextpage.="<a rel="nofollow noopener noreferrer" href='".$purl."/$nextpagenum.html'>下一页</a>\r\n";
	$endpage="<a rel="nofollow noopener noreferrer" href='".$purl."/$totalpage.html'>末页</a>\r\n";
	

3.修改\include\arc.taglist.class.php文件,大概在509行,把:

	
	$listdd.="<li><a rel="nofollow noopener noreferrer" href='".$purl."/$j/'>".$j."</a></li>\r\n";
	

修改为(其实就是在链接后加了个后缀.html):

	
	$listdd.="<a rel="nofollow noopener noreferrer" href='".$purl."/$j.html'>".$j."</a>\r\n";
	

4.IIS6.0服务器伪静态规则中写:

	
	RewriteRule ^(.*)/tags/(.*)\/([0-9]+)\.html $1/tags.php?/$2/$3/
	

IIS7.0及以上服务器伪静态规则中写:

	
	<rule name="Redirecttagsl" stopProcessing="true">
	            <match url="^tags/(\w+)/([0-9]*).html"/>
	             <action type="Rewrite" url="tags.php?/{R:1}/{R:2}"/>
	          </rule>
	

Apache服务器伪静态规则中写 :

	
	RewriteRule ^tags/(.*)\/([0-9])(?:(\?.*))*\.html$ tags\.php\?\/$1\/$2
	RewriteRule ^tags/(.*)\/([0-9])\/(?:(\?.*))*\.html$ tags\.php\?\/$1\/$2\/
	

这样就完美实现了DedeCMS Tags标签页以及列表分页伪静态,余斗把自己整套Tags页伪静态规则贴出来,大家参考:

IIS6.0服务器伪静态规则:

	
	RewriteRule ^(.*)/tags\.html $1/tags\.php
	RewriteRule ^(.*)/tags/(.*).html $1/tags\.php\?$2
	RewriteRule ^(.*)/tags/(.*)\/([0-9]+)\.html $1/tags.php?/$2/$3/
	

IIS7.0及以上服务器伪静态规则:

	
	<rule name="Redirecttagsl" stopProcessing="true">
	  <match url="^tags/(\w+)/([0-9]*).html"/>
	     <action type="Rewrite" url="tags.php?/{R:1}/{R:2}"/>
	  </rule>
	  <rule name="Redirecttags1" stopProcessing="true">
	<match url="^tags/(\w+).html"/>
	    <action type="Rewrite" url="tags.php?/{R:1}"/>
	      </rule>
	    <rule name="Redirecttags" stopProcessing="true">
	 <match url="^tags.html"/>
	      <action type="Rewrite" url="tags.php"/>
	    </rule>
	

Apache服务器伪静态规则 :

	
	RewriteRule ^tags.html/tags.php
	RewriteRule ^tags/(.*)(?:(\?.*))*\.html$ tags\.php\?\/$1
	RewriteRule ^tags/(.*)\/(?:(\?.*))*\.html$ tags\.php\?\/$1\/
	RewriteRule ^tags/(.*)\/([0-9])(?:(\?.*))*\.html$ tags\.php\?\/$1\/$2
	RewriteRule ^tags/(.*)\/([0-9])\/(?:(\?.*))*\.html$ tags\.php\?\/$1\/$2\/
	

本文DedeCMS Tags标签页以及列表分页伪静态如何实现到此结束。人生的游戏不在于拿了一副好牌,而在于怎样去打好坏牌,世上没有常胜将军,勇于超越自我者才能得到最后的奖杯。小编再次感谢大家对我们的支持!

您可能有感兴趣的文章
织梦后台文档列表添加复制文档功能支持所有模型

织梦无法上传ico图标格式文件的如何解决方法

dedecms如何实现任意页面调用当前会员信息的方

织梦dede:tag调用指定多个栏目的TAG标签

织梦栏目列表按附加表自定义字段排序