织梦DedeCMS实现tag标签伪静态为id.html
织梦DedeCMS的tag标签系统默认是/tags.php?/tag标签/,不利于SEO优化,此教程教大家设置TAG标签页为伪静态,并且是单链接/id.html的形式。
链接形式
TAG标签页 /tags/9.html
TAG标签分页 /tags/9_2.html
PC端TAG伪静态实现教程
1、/tags.php 找到 18行
if(isset($tags[2])) $PageNo = intval($tags[2]);
在它下面加入
$tagid = (isset($tag) && is_numeric($tag)) ? intval($tag) : 0;
if(!empty($tagid))
{
$row = $dsql->GetOne("SELECT tag FROM `#@__tagindex` WHERE id = {$tagid}");
if(!is_array($row))
{
ShowMsg("系统无此标签,可能已经移除!","-1");exit();
}
else
{
$tag = $row['tag'];
define('DEDERETAG', 'Y');
}
}
else
{
$tag = '';
}
2、/include/taglib/tag.lib.php 找到 87行
$row['link'] = $cfg_cmsurl."/tags.php?/".urlencode($row['keyword'])."/";
改成
$row['link'] = $cfg_cmsurl."/tags/".$row['id'].".html";
3、/include/arc.taglist.class.php 找到 458行
$purl .= "?/".urlencode($this->Tag);
改成
if(!defined('DEDERETAG'))
{
$purl .= "?/".urlencode($this->Tag);
}
继续找到
return $plist;
在它上面加入
if(defined('DEDERETAG'))
{
$plist = preg_replace('/_(d+).html/i','.html',$plist);
$plist = preg_replace('/.html/(d+)//i','_1.html',$plist);
}
4、TAG标签伪静态规则,根据自己网站的主机环境选择下面的规则
.htaccess (Apache)
RewriteEngine On
RewriteBase /
RewriteRule ^tags.html$ tags.php
RewriteRule ^tags/([0-9]+).html$ tags.php?/$1 [L]
RewriteRule ^tags/([0-9]+).html$ tags.php?/$1/
RewriteRule ^tags/([0-9]+)_([0-9]+).html$ tags.php?/$1/$2
RewriteRule ^tags/([0-9]+)_([0-9]+).html$ tags.php?/$1/$2/
Nginx
#TAG标签伪静态规则 Nginx
rewrite ^/tags.html$ /tags.php;
rewrite ^/tags/([0-9]+).html$ /tags.php?/$1;
rewrite ^/tags/([0-9]+).html$ /tags.php?/$1/;
rewrite ^/tags/([0-9]+)_([0-9]+).html$ /tags.php?/$1/$2;
rewrite ^/tags/([0-9]+)_([0-9]+).html$ /tags.php?/$1/$2/;
完成。
本文链接:http://78moban.cn/post/14296.html
版权声明:站内所有文章皆来自网络转载,只供模板演示使用,并无任何其它意义!